【发布时间】:2021-05-07 13:40:03
【问题描述】:
我正在使用 Terraform 0.14.2 开发一个 API 项目。我想创建一个输出来打印我可以在开发 API 时使用的调试 CURL 命令。
这是我尝试输出的示例
curl -X POST -H 'Content-Type: application/json' -d '{"test": "yes"}' https://foo.bar.baz
我的 Terraform 输出如下所示:
output "test" {
value = "curl -X POST -H 'Content-Type: application/json' -d '${jsonencode({test = "yes"})}' https://foo.bar.baz"
}
Terraform 对此很满意,但它会生成以下实际输出
cur -X POST -H 'Content-Type: application/json' -d '{\"test\": \"yes\"}' https://foo.bar.baz
我尝试手动编写 JSON:
output "test" {
value = "curl -X POST -H 'Content-Type: application/json' -d '{\"test\" = \"yes\"}' https://foo.bar.baz"
}
但我得到相同的输出。字符串转义在 terraform 中的工作方式是否与其他所有语言不同?举一个更简单的例子,使用这个 terraform:
output "quote" {
value = "\""
}
这输出"\"" 我希望它输出"
【问题讨论】:
标签: terraform