英文:
How to get all output values from map variable in terraform?
问题
我尝试从子模块中提取id
变量,以将其传递给另一个子模块。我的networking
模块中的输出块如下所示:
output "database_subnets_properties" {
description = "List of all* Database Subnets Properties"
value = tomap({
for k, subnet in aws_subnet.database : k => {
arn = subnet.arn
id = subnet.id
}
})
}
我需要将这个输出的ID传递给lambda的vpc_config
块。VPC配置块如下所示:
vpc_config {
subnet_ids = var.database_subnets_ids
security_group_ids = [aws_security_group.for_lambda.id]
}
如果我像这样传递它们:
database_subnets_ids = [module.networking.database_subnets_properties[0].id, module.networking.database_subnets_properties[1].id, module.networking.database_subnets_properties[2].id]
在main.tf
中,它能够正常工作。我无法找到如何通过实现循环或类似方法来改进这段代码的解决方案。您能否提供建议?提前谢谢。
英文:
I'm trying to extract id variable from child module to pass it to another child module. My output block in networking
module is looking like
output "database_subnets_properties" {
description = "List of all* Database Subnets Properties"
value = tomap({
for k, subnet in aws_subnet.database : k => {
arn = subnet.arn
id = subnet.id
}
})
}
I need to pass IDs from this output to lambda vpc_config
block.
VPC config block looks like
vpc_config {
subnet_ids = var.database_subnets_ids
security_group_ids = [aws_security_group.for_lambda.id]
}
If I pass them like
database_subnets_ids = [module.networking.database_subnets_properties[0].id, module.networking.database_subnets_properties[1].id, module.networking.database_subnets_properties[2].id]
in main.tf, it's working.
I can't find a solution how to improve this code with implementing loop or something like that.
Could you please advise?
Thank you in advance
答案1
得分: 1
你可以使用 splat 表达式:
database_subnets_ids = values(module.networking.database_subnets_properties)[*].id
英文:
You can use splat expression:
database_subnets_ids = values(module.networking.database_subnets_properties)[*].id
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论