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

Why terraform thinks that I changed many atttributes from "" to null?

我刚刚执行了 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"