Terraform将关键点与两个不同的地图进行比较并复制值
我有一个模块,输出map,Terraform将关键点与两个不同的地图进行比较并复制值,terraform,terraform-provider-aws,Terraform,Terraform Provider Aws,我有一个模块,输出map,模块.platformusers.path,如下所示: { "user1_test" = "user1_value_path" "user2_test" = "user2_value_path" "user3_test" = "user3_value_path" } 我必须迭代local.musyersmap并获取键并与mod
模块.platformusers.path,如下所示:
{
"user1_test" = "user1_value_path"
"user2_test" = "user2_value_path"
"user3_test" = "user3_value_path"
}
我必须迭代local.musyers
map并获取键并与module.platformusers.path
key进行比较,如果键包含在第二个map中,则必须复制值
{
"user1" = "Allen"
"user2" = "john"
"user3" = "Rose"
}
当我假设这些是个人的时候,我想要这样的东西
resource "aws_ssm_parameter" "userspath" {
name = "Allen"
type = "String"
value = "user1_value_path"
}
resource "aws_ssm_parameter" "userspath" {
name = "john"
type = "String"
value = "user2_value_path"
}
resource "aws_ssm_parameter" "userspath" {
name = "Rose"
type = "String"
value = "user3_value_path"
}
我正在按此处所示进行尝试,但无法正常工作,因为我的钥匙不完全匹配:
resource "aws_ssm_parameter" "userspath" {
for_each = module.platformusers.paths
name = ${each.value}
type = "String"
value = lookup( module.platformusers.paths, ${each.key}, "")
}
如何在此处应用contains?可能有更好的方法,但这里有一个我可以想到的快速方法。。
如果键之间的差异只是“_test”,正如上面所示,那么实际上可能很简单。您可以使用format函数添加“_test”并进行查找
在示例代码中,您没有针对local.musyers进行循环。。
注意:它区分大小写。可以使用UPPER函数使其不敏感
resource "aws_ssm_parameter" "userspath" {
for_each = local.musyers
name = ${each.value}
type = "String"
value = lookup(module.platformusers.paths, format("%s_test", each.key) , "missing")
}