在地形中,如何使用地图列表列表?
In terraform, How to use list of list of map?
我想在 terraform 中使用地图列表列表。
我有 3 个环境,每个环境有多个子网。
segmented_subnets = {
rest = {
dev = [
"subnet-", #a
"subnet-", #b
]
qa = [
"subnet-"
"subnet-"
]
}
dashboard = {
dev = [
"subnet-",
"subnet-",
]
qa = [
"subnet-"
"subnet-"
]
}
login = {
dev = [
"subnet-",
"subnet-",
]
qa = [
"subnet-"
"subnet-"
]
}
}
我想访问这些子网,
我试过了:
"${element(var.segmented_subnets.rest.["${terraform.workspace}"], count.index)}"
或:
"$${element(var.segmented_subnets.rest.["${terraform.workspace}"], count.index)}"
无法访问这个变量
已完成数据使用:
data "aws_subnet_ids" "foo" {
vpc_id = "${var.vpcs["${terraform.workspace}"]}"
tags {
Name = "bar*"
}
}
使用者:
resource "aws_instance" "ec2-foo" {
...
instance_type = "t2.small"
subnet_id = "${data.aws_subnet_ids.foo.ids[count.index]}"
...
我想在 terraform 中使用地图列表列表。 我有 3 个环境,每个环境有多个子网。
segmented_subnets = {
rest = {
dev = [
"subnet-", #a
"subnet-", #b
]
qa = [
"subnet-"
"subnet-"
]
}
dashboard = {
dev = [
"subnet-",
"subnet-",
]
qa = [
"subnet-"
"subnet-"
]
}
login = {
dev = [
"subnet-",
"subnet-",
]
qa = [
"subnet-"
"subnet-"
]
}
}
我想访问这些子网, 我试过了:
"${element(var.segmented_subnets.rest.["${terraform.workspace}"], count.index)}"
或:
"$${element(var.segmented_subnets.rest.["${terraform.workspace}"], count.index)}"
无法访问这个变量
已完成数据使用:
data "aws_subnet_ids" "foo" {
vpc_id = "${var.vpcs["${terraform.workspace}"]}"
tags {
Name = "bar*"
}
}
使用者:
resource "aws_instance" "ec2-foo" {
...
instance_type = "t2.small"
subnet_id = "${data.aws_subnet_ids.foo.ids[count.index]}"
...