【问题标题】:VPC Peering is replaced all the time by TerraformVPC Peering 一直被 Terraform 取代
【发布时间】:2022-09-30 12:20:21
【问题描述】:

我正在尝试在两个不同账户中的两个 VPC 之间创建 VPC 对等互连。一个由我管理,另一个由其他人管理,我无权访问它。 我正在使用 Terraform 脚本的下一个 sn-p。

resource \"aws_vpc_peering_connection\" \"a\" {
  peer_owner_id = var.a.aws_account_id
  peer_vpc_id   = var.a.vpc_id
  vpc_id        = aws_vpc.main.id
  peer_region   = \"eu-west-1\"

  requester {
    allow_remote_vpc_dns_resolution = false
  }
}

接下来,管理该帐户的人将手动接受它。 问题是 Peering 是否被接受 Terraform 想要 replace 那个 Peering 连接:

  # module.vpc.aws_vpc_peering_connection.a is tainted, so must be replaced
-/+ resource \"aws_vpc_peering_connection\" \"a\" {
      ~ accept_status = \"active\" -> (known after apply)
      ~ id            = \"pcx-00000000000000000\" -> (known after apply)
        # (5 unchanged attributes hidden)

      + accepter {
          + allow_classic_link_to_remote_vpc = (known after apply)
          + allow_remote_vpc_dns_resolution  = (known after apply)
          + allow_vpc_to_remote_classic_link = (known after apply)
        }

        # (1 unchanged block hidden)
    }

我已经尝试使用lifecycle 来阻止替换

  lifecycle {
    ignore_changes = all
  }

但这无济于事...

    标签: amazon-web-services terraform terraform-provider-aws aws-vpc-peering vpc-peering


    【解决方案1】:

    尝试清除资源,例如

    terraform untaint aws_vpc_peering_connection.a
    

    【讨论】:

      【解决方案2】:

      通过使用 aws_vpc_peering_connection_options 资源而不是在 aws_vpc_peering_connection 请求者中指定选项,当 Terraform 注意到 allow_remote_vpc_dns_resolution 选项已更改时,我能够避免重新创建连接本身。

      https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_peering_connection_options

      在对方接受对等连接之前,设置该选项仍然会失败,但是一旦您在对方帐户上接受了连接,只有选项会被污染,而不是整个连接。

      【讨论】:

        猜你喜欢
        • 2017-03-19
        • 2019-11-27
        • 1970-01-01
        • 2021-07-01
        • 2020-05-06
        • 2017-09-21
        • 2015-12-04
        • 2021-09-02
        • 2019-07-14
        相关资源
        最近更新 更多