如何使用Terraform12将映射变量解析为资源值中的字符串?
我有这个变量:
variable "tags" {
type = map
default = {
deployment_tool = "Terraform"
code = "123"
}
}
并希望这样做:{deployment_tool = Terraform,代码= 123}
我尝试了以下失败的事情:
resource "aws_ssm_parameter" "myparamstore" {
***
value = {
for tag in var.tags:
join(",",value, join("=",tag.key,tag.values))
}
}
答案 0 :(得分:3)
将“:”替换为不是完美的解决方案,只需考虑具有这样值的映射:select t.*, v.*
from t outer apply
(select max(case when seqnum = 1 then col end) as col1,
max(case when seqnum = 2 then col end) as col2,
max(case when seqnum = 3 then col end) as col3
from (select v.col,
row_number() over (order by v.col desc) as seqnum
from (values (t.col1), (t.col2), (t.col3)
) v(col)
) v
) v;
- 变为APPLY
。那不好。
所以这是我的解决方案:
case
答案 1 :(得分:2)
您请求的输出只是格式错误的JSON字符串。因此,您可以使用jsonencode
将变量转换为json,然后删除"
并将:
更改为=
:
value = replace(replace(jsonencode(var.tags), "\"", ""), ":", "=")