json - 将 terraform HCL 变量 type=map(any) 转换为 JSON
问题描述
我正在尝试将用 HCL 编写的 terraform 变量转换为tf.json
包含该变量的动态生成的文件,但我遇到了错误。
我正在尝试转换的 HCL 版本:
variable "accounts" {
type = map(any)
default = {
acct1 = ["000000000001"]
acct2 = ["000000000002"]
}
}
我尝试了以下格式:
{
"variable": {
"accounts": {
"type": "map(any)",
"default": [
{ "acct1": "000000000001" },
{ "acct2": "000000000002"}
]
}
}
}
和
{
"variable": {
"accounts": {
"type": "map(any)",
"default": [
{
"acct1": ["000000000001"],
"acct2": ["000000000002"]
}
]
}
}
}
我收到以下错误:
│ Error: Invalid default value for variable
│
│ on accounts.tf.json line 6, in variable.accounts:
│ 6: "default": [
This default value is not compatible with the variable's type constraint: map of any single type required.
是否有将 HCL 转换为有效.tf.json
配置的工具?或者我在这里的格式缺少什么?
解决方案
您的默认值是地图列表,但它应该只是地图:
"default": {
"acct1": "000000000001",
"acct2": "000000000002"
}
推荐阅读
- java - 在 Api 请求使用 Query 返回数据时显示加载图像
- rtai - RTAI:编写数据结构的模块内核
- azure-devops - TFS build vNext 允许在队列时间更改不可设置的变量
- javascript - 在 javascript 和 angularjs 中将键对象与字符串值进行比较
- android - 我们如何将上下文转换为片段?
- jmeter - 未创建 JMeter 报告文件夹:“预期列数不匹配”
- python - 如何使用 Python + Selenium 在 JavaScript 中获取 href 值
- sql-server - SQL Server 自动索引调整功能是否会删除唯一索引?
- tabs - 你能解释一下使用制表符和空格的区别吗?
- php - PHP 连接到远程 MSSQL 但得到错误列表