terraform - 在 Terraform 的输出字符串中转义引号
问题描述
我正在使用 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 output -raw test
但是,我不确定您是否可以强制terraform apply
使用原始输出,而不是转义输出。
推荐阅读
- python - 从数据框中列的字符串值中获取 int 值
- python - TA-Lib 抽象 API 的好处
- c# - 序列化对象时如何忽略 JsonPropertyNameAttribute 注释?
- ios - 协议委托未给出预期结果
- javascript - div 在水平滚动时根据 offsetLeft 获取类
- javascript - setinterval 内的函数需要超过超时时间
- c# - 为什么修改此字符串也会修改另一个单独字符串的内容?
- python - 熊猫点对象
- vue.js - 如何使 Vue 中的表头可点击?
- java - 在 Adapter Android Studio 中使用全局变量