如何在Terraform中添加和引用地图作为局部变量的地图?
我想创建地图作为本地变量。我现在正在使用它,
locals {
region_map = {
mumbai = {
is_second_execution = true
cg_ip_address = "ip.add.re.ss"
}
}
}
我将其称为,
module "mumbai" {
source = "./site-to-site-vpn-setup"
providers = { aws = aws.mumbai }
is_second_execution = lookup(local.region_map, local.region_map["mumbai"]["is_second_execution"], false)
cg_ip_address = lookup(local.region_map, local.region_map["mumbai"]["cg_ip_address"], "")
}
但是在进行Terrafrom计划时,CG_IP_ADDRESS将设置为null。 另外,如果我添加了另一个模块说“ saopaulo”,并且需要传递is_second_execution的默认值和cg_ip_address,而无需在地图中添加saopaulo,我该怎么做?
I want to create a map of map as a local variable. I am using this
locals {
region_map = {
mumbai = {
is_second_execution = true
cg_ip_address = "ip.add.re.ss"
}
}
}
Now I am referencing it as
module "mumbai" {
source = "./site-to-site-vpn-setup"
providers = { aws = aws.mumbai }
is_second_execution = lookup(local.region_map, local.region_map["mumbai"]["is_second_execution"], false)
cg_ip_address = lookup(local.region_map, local.region_map["mumbai"]["cg_ip_address"], "")
}
but upon doing terrafrom plan the cg_ip_address is being set to null.
Also If I add another module say "saopaulo" and I need to pass default values of is_second_execution and cg_ip_address for it without adding saopaulo in the map, how do I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查找
内置函数[1]具有以下语法:由于您有一个映射地图,这意味着第一个参数是映射(
locion.region_map.mumbai
),第二个是您正在寻找的密钥(cg_ip_address
),第三个参数是默认值。因此,在您的情况下,您必须将查找更改为:[1] https:// https:// www。 terraform.io/language/functions/lookup
The
lookup
built-in function [1] has the following syntax:Since you have a map of maps, that means that the first argument is the map (
local.region_map.mumbai
), the second is the key you are looking for (cg_ip_address
) and the third argument is the default value. So in your case you have to change the lookup to this:[1] https://www.terraform.io/language/functions/lookup