我有用Terraform创建的基础设施。将有一些自动标度组(AWS)或实例组(GCP),这取决于云提供商。它不直接管理实例。
我希望编写一个AWS或gcloud命令,将自动标度减少到最小0,最大值0,删除健康检查,基本上所有与实例组相关的内容。然后等待组删除所有实例。然后,我手动将所有内容更改回原来的设置。
发布于 2021-08-26 22:10:52
你真的可以做到。但是,IaC工具侧重于“所需的状态”。通过更改缩放/耗尽资源,您可以在Terraform之外执行此操作。然后,在标识您的资源已耗尽之后,让Terraform将基础结构返回到所需的状态。
类似的东西(但仍然使用IaC )是将terraform本地states定义为local变量。然后,来回切换状态。
示例:
# define the states
locals {
instance_state {
draining {
min_instances = 0
max_instances = 0
health_check = false
}
black_friday {
min_instances = 20
max_instances = 100
health_check = true
}
default {
min_instances = 5
max_instances = 20
health_check = true
}
}
}
# You set the state here...
locals {
desired_state = local.instance_state.draining
}然后,在资源中使用desired_state
# No change needed here since it points to the desired_state
resource "type_some_resource" "resource_name" {
min_instances = local.desired_state.min_instances
max_instances = local.desired_state.max_instances
health_check = local.desired_state.health_check
}https://stackoverflow.com/questions/68945038
复制相似问题