我试图按照以下说明使用Heredoc语法作为字符串变量的值
variable "docker_config" {
type = "string"
default = <<EOF
{ "auths": { "https://index.docker.io/v1/": { "auth": "****" } } }
EOF
}
这不会导致Terraform产生错误,但是稍后在远程执行命令中使用该变量时“ echo $ {var.docker_config}> /home/ubuntu/.docker/config.json “ ,该值为空。
这是在变量中使用Heredoc语法的正确方法吗?
答案 0 :(得分:1)
您不能在变量中执行heredoc。您可以在局部变量中完成此操作。
locals {
docker_config = <<EOF
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "****"
}
}
}
EOF
}
output "docker_config" {
value = "${local.docker_config}"
}
$ terraform apply
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
docker_config = {
"auths": {
"https://index.docker.io/v1/": {
"auth": "****"
}
}
}