英文:
Would like to identify subnet names to create a map in terraform
问题
我一直在尝试找到一种方法从AWS中获取子网的名称,但是到目前为止没有成功。我可以找到ARN、ID、CIDR等等其他信息,但是没有名称。希望能得到帮助!
我想要实现的目标是创建一个子网映射,其中子网名称作为键,子网ID作为值。显然,data.aws_subnet
不支持名称属性。我已经在"谷歌"上搜索了很多,但没有找到解决办法。
data "aws_subnets" "private" {
tags = {
Name = "private*"
}
filter {
name = "state"
values = ["available"]
}
}
data "aws_subnet" "private" {
for_each = toset(data.aws_subnets.private.ids)
id = each.value
}
# 想要创建一个映射,以子网名称作为键,子网ID作为值... 但是,名称是不支持的属性。
private_subnet_ids = { for s in data.aws_subnet.private : trimprefix(s.name, "private") => s.id }
英文:
I've been trying to find a way to get the subnet names of out of aws... so far no luck. I can find the arn, ids, cidrs... and a bunch of other stuff. But, not names. Help is appreciated!
This is what I'm aiming for. To create a subnet map with the subnet name as the key, and the subnet id as the value. Obviously name IS NOT a supported attribute of data.aws_subnet
. I have scoured the 'google' with not luck.
data "aws_subnets" "private" {
tags = {
Name = "private*"
}
filter {
name = "state"
values = ["available"]
}
}
data "aws_subnet" "private" {
for_each = toset(data.aws_subnets.private.ids)
id = each.value
}
# wanting to create a map with subnet.name => subnet.id... but, name is an unsupported attribute.
private_subnet_ids = { for s in data.aws_subnet.private : trimprefix(s.name, "private") => s.id }
答案1
得分: 0
你必须使用tags["Name"]
:
private_subnet_ids = { for s in data.aws_subnet.private : trimprefix(s.tags["Name"], "private") => s.id }
英文:
You have to use tags["Name"]
:
private_subnet_ids = { for s in data.aws_subnet.private : trimprefix(s.tags["Name"], "private") => s.id }
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论