【问题标题】:Revoke client vpn ingress on destroy在销毁时撤销客户端 vpn 入口
【发布时间】:2021-03-25 12:08:39
【问题描述】:

我正在尝试撤销 Terrafrom 中“销毁”的 vpn 客户端入口规则。 terraform 0.12 一切正常 不幸的是,升级到 0.14 版后,同样的方法不再有效。 这是我所拥有的:

resource "null_resource" "client_vpn_ingress" {
  provisioner "local-exec" {
    when = create
    command = "aws ec2 authorize-client-vpn-ingress --client-vpn-endpoint-id ${aws_ec2_client_vpn_endpoint.vpn_endpoint.id} --target-network-cidr ${var.vpc_cidr_block} --authorize-all-groups --region ${var.aws_region} --profile ${var.profile}"
}
  provisioner "local-exec" {
    when = destroy
    command = "aws ec2 revoke-client-vpn-ingress --client-vpn-endpoint-id ${aws_ec2_client_vpn_endpoint.vpn_endpoint.id} --target-network-cidr ${var.vpc_cidr_block} --revoke-all-groups --region ${var.aws_region} --profile ${var.profile}"
}
}

这是错误信息:

错误:来自销毁配置器的无效引用

在 vpn_client_endpoint.tf 第 84 行,在资源“null_resource”中 “client_vpn_ingress”:84:命令=“aws ec2 撤销-client-vpn-ingress --client-vpn-endpoint-id ${aws_ec2_client_vpn_endpoint.vpn_endpoint.id} --target-network-cidr ${var.vpc_cidr_block} --revoke-all-groups --region ${var.aws_region} --profile ${var.profile}"

销毁时供应商及其连接配置只能 相关资源的引用属性,通过“自我”, “count.index”或“each.key”。

在销毁阶段对其他资源的引用可能会导致 依赖循环并且与 create_before_destroy 交互不佳。

很遗憾,我无法再使用 Terraform 0.12

有谁知道如何在版本 >= 0.14 的“terraform destroy”上撤销它?

【问题讨论】:

    标签: amazon-web-services terraform


    【解决方案1】:

    从 Terraform AWS 提供商的 2.70.0 版开始(请参阅 this GitHub comment),您现在可以执行以下操作:

    resource "aws_ec2_client_vpn_authorization_rule" "vpn_auth_rule" {
      depends_on             = [
        aws_ec2_client_vpn_endpoint.vpn
      ]
      client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.vpn.id
      target_network_cidr    = "0.0.0.0/0"
      authorize_all_groups   = true
    }
    

    这样,入口规则将被 Terraform 作为状态中的一等资源处理,您不必担心是否/何时执行命令。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-26
      • 1970-01-01
      • 1970-01-01
      • 2020-02-09
      • 2016-12-06
      • 2016-05-12
      相关资源
      最近更新 更多