google-cloud-platform - Terraform 在 terraform 之外手动更改自动缩放组/实例组
问题描述
我有使用 Terraform 创建的基础设施。根据云提供商的不同,会有一些自动扩展组 (AWS) 或实例组 (GCP)。它不直接管理实例。
我想编写一个 AWS 或 gcloud 命令来将自动缩放减少到最小 0,最大 0,删除运行状况检查,基本上是与实例组相关的所有其他内容。然后等待组删除所有实例。然后我手动将所有内容更改回原始设置。
- 这个腐败的 terraform 状态会不会?
- 这样做之后,这是否被认为是漂移?
- terraform 可以处理这个问题还是会创建一个僵尸资源?
- 这是反模式吗?
解决方案
你确实可以做到这一点。然而,IaC 工具专注于“期望的状态”。通过更改扩展/消耗资源,您可以在 Terraform 之外执行此操作。然后,在确定您的资源已耗尽后,让 Terraform 将基础设施恢复到所需的状态。
类似但仍使用 IaC 的东西将 terraform local 定义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
}
推荐阅读
- ios - 如何从 touchesMoved 方法获得准确的 CGpoint 以在场景视图上绘制 UIBezierpath?
- python-3.x - 如何在for循环中遍历多个字符串变量?
- c# - 转换/转换为 SuperType 方差
- c++ - 指针输出的虚拟值
- c# - 尝试优化 linq 查询
- python - 最大素数的最快解决方案
- mysql - 如何从具有多对多关系的表中选择最新记录
- android - 找不到 com.android.tools.build:gradle:5.1.1
- postgresql - 外部值在数据库中作为空白插入。如何解决这个问题?
- android - 有一个库,我使用 react-native-pie 进行饼图聊天