amazon-web-services - 在销毁时撤销客户端 vpn 入口
问题描述
我正在尝试撤销 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: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}"
销毁时供应商及其连接配置只能通过“self”、“count.index”或“each.key”引用相关资源的属性。
在销毁阶段对其他资源的引用可能会导致依赖循环并与 create_before_destroy 交互不良。
不幸的是,我不再能够使用 Terraform 0.12
有谁知道如何在版本 >= 0.14 的 'terraform destroy' 上撤销它?
解决方案
从 Terraform AWS 提供商的 2.70.0 版本开始(请参阅此 GitHub 评论),您现在可以执行以下操作:
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 作为状态中的一流资源处理,您不必担心是否/何时执行命令。
推荐阅读
- vuejs2 - [vuex]未知动作类型:getPackagingList
- javascript - AnimationFrames 的新手,绘制新图像时需要删除以前的图像,怎么办?
- mysql - MySQL:带有 WHERE 子句的 SUM
- python - 无法将每个单元格中带有 numpy 数组的 pandas 列转换为 tensorflow 张量
- graphql - Kickstart graphql 服务器订阅不起作用
- unix - 如何将一个 csv 列转换为 n 个包含相等行且每个文件包含标题作为 id 的 csv 文件?
- php - 如何在 N 天后自动删除 WooCommerce 商店的过期优惠券?
- mysql - 创建触发器以运行程序以检查限制
- ios - extensionContext!.completeRequest 将 nil 项返回给 Host-App
- reactjs - 如何在反应中添加带有表情符号的草稿编辑器?