我想在 Terraform 0.12 中连接两个数组。在我的示例中,有公共和私有子网。我想将它们分配给相同的网络访问列表。以下代码缩短:
data "aws_subnet_ids" "private" {
vpc_id = aws_vpc.main.id
tags = {
subnet-type = "private"
}
}
data "aws_subnet_ids" "public" {
vpc_id = aws_vpc.main.id
tags = {
subnet-type = "public"
}
}
resource "aws_network_acl" "networks" {
vpc_id = aws_vpc.main.id
subnet_ids = concat(data.aws_subnet_ids.private.ids, data.aws_subnet_ids.public.ids)
[...]
}
Run Code Online (Sandbox Code Playgroud)
如果我使用以下输出:
output "private_subnets" {
value = data.aws_subnet_ids.private.ids
}
output "public_subnets" {
value = data.aws_subnet_ids.public.ids
}
Run Code Online (Sandbox Code Playgroud)
生成以下输出:
private_subnets = [
"subnet-243zr427rhhfjseb9",
"subnet-we789rh2438fchb6e",
"subnet-092rz7g82fhhkui74",
]
public_subnets = [
"subnet-12230qegvg764e9d",
"subnet-123465svgvgf0d7e",
]
Run Code Online (Sandbox Code Playgroud)
所以一切都应该有效。但是给出了以下错误:
iptizer@machine:~/src/infra$ terraform12 apply …Run Code Online (Sandbox Code Playgroud) 我无法通过任何其他方法解决这个问题,所以我必须在这里问这个......
在 Terraform 0.11 中将地图分配给值时使用等号 (=) 背后的逻辑是什么?
与 =
resource "pseude_resource" "pseudo_name" {
value = {
key1 = value1
key2 = value2
}
}
Run Code Online (Sandbox Code Playgroud)
没有 =
resource "pseude_resource" "pseudo_name" {
value {
key1 = value1
key2 = value2
}
}
Run Code Online (Sandbox Code Playgroud)
使用数组 ([]) 时似乎需要使用 =,但使用映射时则不需要。这背后的原因是什么?到底为什么?可以直接省略吗?