terraform - 为什么 terraform 认为我将许多属性从 ""更改为 null?

标签 terraform terraform-provider-aws

我刚刚执行了 terraform plan,它报告了很多虚假的变化。它报告说它需要重新创建大量资源,因为一些 ""(空字符串)的属性不是 null

例如它认为我改变了这条路线

route            = [
      - {
          - cidr_block                = "0.0.0.0/0"
          - egress_only_gateway_id    = ""
          - gateway_id                = "igw-xxxx"
          - instance_id               = ""
          - ipv6_cidr_block           = ""
          - nat_gateway_id            = ""
          - network_interface_id      = ""
          - transit_gateway_id        = ""
          - vpc_peering_connection_id = ""
        },
      + {
          + cidr_block                = "0.0.0.0/0"
          + egress_only_gateway_id    = null
          + gateway_id                = "igw-xxxx"
          + instance_id               = null
          + ipv6_cidr_block           = null
          + nat_gateway_id            = null
          + network_interface_id      = null
          + transit_gateway_id        = null
          + vpc_peering_connection_id = null
        },

据我所知,没有实际变化(在 terraform 配置中)所以我怀疑 这一定是商店状态与 Terraform 如何计算“所需”状态之间存在差异。

这是什么原因造成的?这是 terraform 0.13.1 和 0.13.5 之间的变化吗?

最佳答案

我遇到了同样的问题。此回复确定了解决方法:https://discuss.hashicorp.com/t/terraform-wants-to-replace-many-resources-because-it-detects-that-null/17845/2

我不确定这个错误是何时或如何引入 AWS 提供商的,但在从 0.11.14 升级到 0.12.28 后它突然出现了。

如果您显式定义所有这些空值,Terraform 将不再将此视为更改。

   route {
-    cidr_block = "0.0.0.0/0"
-    gateway_id = "igw-ID"
+    cidr_block                = "0.0.0.0/0"
+    gateway_id                = "igw-ID"
+    egress_only_gateway_id    = ""
+    instance_id               = ""
+    ipv6_cidr_block           = ""
+    nat_gateway_id            = ""
+    network_interface_id      = ""
+    transit_gateway_id        = ""
+    vpc_peering_connection_id = ""

将我的计划从销毁并重新创建所有路线更改为仅添加一条新路线(匿名值):

  # aws_route_table.main-vpc-ID will be updated in-place
  ~ resource "aws_route_table" "main-vpc-ID" {
        id               = "rtb-ID"
        owner_id         = "accountid"
        propagating_vgws = []
      ~ route            = [
            {
                cidr_block                = "0.0.0.0/0"
                egress_only_gateway_id    = ""
                gateway_id                = "igw-ID"
                instance_id               = ""
                ipv6_cidr_block           = ""
                nat_gateway_id            = ""
                network_interface_id      = ""
                transit_gateway_id        = ""
                vpc_peering_connection_id = ""
            },
          + {
              + cidr_block                = "10.100.2.0/24"

关于terraform - 为什么 terraform 认为我将许多属性从 ""更改为 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64911577/

相关文章:

terraform - 亚特实验室 CI : terraform destroy doesn't destroy?

azure - 有条件的 Terraform 部署模块

amazon-web-services - VPCId 未指定 : No default VPC for this user error when doing terraform apply

amazon-web-services - Terraform 破坏错误 'Instance cannot be destroyed' 和 'Failed getting S3 bucket'

amazon-web-services - Terraform : Error reason: The ARN isn't valid. 有效的 ARN 以 arn: 开头,并包含由冒号或斜杠分隔的其他信息

terraform - terraform 是否允许我们覆盖变量

docker - 创建本地端到端开发环境

Terraform:Flatcar OS 容器 Linux 配置的存储部分中的 YAML 文件渲染问题

ubuntu - 使用 terraform 将 ubuntu iso 部署到 proxmox

amazon-web-services - 未找到匹配的 EC2 安全组