【发布时间】:2020-04-06 02:52:27
【问题描述】:
我正在使用 Terraform 启动我的云环境。
似乎即使是很小的配置更改也会影响幕后的许多资源。
例如,在我创建 AWS 实例的情况下 - 一个小的更改将导致所有实例的自动生成:
-/+ aws_instance.DC (new resource required)
id: "i-075deb0aaa57c2d" => <computed> (forces new resource) <----- How can we avoid that?
ami: "ami-01e306baaaa0a6f65" => "ami-01e306baaaa0a6f65"
arn: "arn:aws:ec2:ap-southeast-2:857671114786:instance/i-075deb0aaa57c2d" => <computed>
associate_public_ip_address: "false" => <computed>
availability_zone: "ap-southeast-2a" => <computed>
.
.
我的问题专门与作为提供商的 AWS 有关:
我们如何避免每次都破坏/创建资源?
可能是 Terraform 中的相关标志?
相关话题:
Terraform > ipv6_address_count: "" => "0" (forces new resource)
terraform > forces new resource on security group
编辑:
在 plan 输出中潜水,似乎其中一个资源发生了变化:
security_groups.#: "0" => "1" (forces new resource)
security_groups.837544107: "" => "sg-0892062659392afa9" (forces new resource)
从如何避免重新创造的角度来看,问题仍然是相关的。
【问题讨论】:
-
ID 更改是替换资源的结果。那里应该有另一个属性标记为
forces new resource。 -
一般来说,控制这种情况的最佳方法是使用
lifecycle块来指定您不想强制使用新资源的属性。 -
谢谢@Adrian 我找到了这个:hashicorp.com/blog/zero-downtime-updates-with-terraform。如果您想对此有所了解,那就太好了(:
-
正如@Adrian 提到的,您需要显示该资源的完整计划输出以显示为什么 Terraform 需要替换资源而不是就地修改它。通常这只是由于 API 不允许以这种方式修改该资源。
标签: amazon-web-services terraform terraform-provider-aws