【发布时间】:2019-08-04 05:32:07
【问题描述】:
刚刚尝试使用新的 terraform aws_route53_resolver_endpoint 资源。它将子网 ID 作为块类型列表。不幸的是,似乎没有办法从从上一步的输出变量读取的子网列表中填充它。
基本上,我使用上一步中的子网资源计数创建了一组子网。我尝试在每个子网中使用这些并设置 aws_route53_resolver_endpoint:
resource "null_resource" "management_subnet_list" {
count = "${length(var.subnet_ids)}"
triggers {
subnet_id = "${element(data.terraform_remote_state.app_network.management_subnet_ids, count.index)}"
}
}
resource "aws_route53_resolver_endpoint" "dns_endpoint" {
name = "${var.environment_name}-${var.network_env}-dns"
direction = "OUTBOUND"
security_group_ids = ["${var.security_groups}"]
ip_address = "${null_resource.management_subnet_list.*.triggers}"
}
上面运行时,会报错:ip_address: should be a list
如果我修改代码如下:
ip_address = ["${null_resource.management_subnet_list.*.triggers}"]
我收到错误:ip_address: attribute supports 2 item as a minimum, config has 1 declared
我似乎想不出任何其他方法来从子网列表动态创建资源列表。
我们将不胜感激。
【问题讨论】:
-
您是否希望子网列表经常更改?如果是这样,只是子网 ID 会改变还是子网数量也会改变?
-
看起来像是 Terraform 0.12 的
forloops 的案例(目前处于测试阶段)。 -
是的,子网列表可以在 2 或 3 之间变化。我正在管理按需 vpc 的创建,并且在每个 VPC 中,团队可以决定使用 2 或 3 个可用区,因此基于子网在 2 或 3 个可用区中,我需要创建出站解析器端点。带有 for 循环的 terraform 0.12 动态块可以工作,但我们现在不能使用 terraform 0.12。
-
没有 v0.12,你可以使用这个github.com/hashicorp/terraform/issues/…
标签: terraform amazon-route53 terraform-provider-aws