使用 heredoc 字符串打印地图变量
Print map variable using heredoc stings
我正在尝试使用 heredoc 示例在 terraform 中打印地图变量:
description = <<EOT
Hello Check ${local.map_variable1} and $local.map_variable2}
EOT
我的地图变量如下:
> local.map_variable1
{
"server_1" = "100.100.50.101"
"server_2" = "100.100.50.102"
"server_3" = "100.100.50.103"
"server_4" = "100.100.50.104"
}
> local.map_variable2
{
"Application_node1" = "100.100.51.101"
"Application_node2" = "100.100.52.102"
"Application_node3" = "100.100.53.103"
"Application_node4" = "100.100.54.104"
}
>
错误:无法在字符串模板中包含给定值:需要字符串。
关于如何打印地图变量的任何建议
最好使用 jsonencode:
将变量转换为 json 字符串
description = <<EOT
Hello Check ${jsonencode(local.map_variable1)} and ${jsonencode(local.map_variable2)}
EOT
我正在尝试使用 heredoc 示例在 terraform 中打印地图变量:
description = <<EOT
Hello Check ${local.map_variable1} and $local.map_variable2}
EOT
我的地图变量如下:
> local.map_variable1
{
"server_1" = "100.100.50.101"
"server_2" = "100.100.50.102"
"server_3" = "100.100.50.103"
"server_4" = "100.100.50.104"
}
> local.map_variable2
{
"Application_node1" = "100.100.51.101"
"Application_node2" = "100.100.52.102"
"Application_node3" = "100.100.53.103"
"Application_node4" = "100.100.54.104"
}
>
错误:无法在字符串模板中包含给定值:需要字符串。
关于如何打印地图变量的任何建议
最好使用 jsonencode:
将变量转换为 json 字符串description = <<EOT
Hello Check ${jsonencode(local.map_variable1)} and ${jsonencode(local.map_variable2)}
EOT