当 json 要求值为整数时,Terraform 插值到 json 文件
Terraform interpolation to json file when json requires value to be integer
正在尝试解决这是否可能。拖网 terraform 文档无济于事(那里并不奇怪)。
以下面的极细线为例。
[
{
"cpu": "${var.master_container_cpu}",
}
]
调用 aws_ecs_task_definition
资源时附加到此 tf 参数;
container_definitions = "${file("task-definitions/example.json")}"
会导致如下错误;
Error: aws_ecs_task_definition.example-task: ECS Task Definition container_definitions is invalid: Error decoding JSON: json: cannot unmarshal string into Go struct field ContainerDefinition.Cpu of type int64
欢迎任何帮助:)
看起来你应该在定义
中使用之前使用template来编译JSON
data "template_file" "task" {
template = "${file("${task-definitions/example.json")}"
vars {
cpu = "${var.master_container_cpu}"
}
}
在 JSON 文件中,您可以使用 ${cpu}
引用变量
然后您就可以使用输出作为您的定义
container_definitions = "${data.template_file.task.rendered}"
正在尝试解决这是否可能。拖网 terraform 文档无济于事(那里并不奇怪)。
以下面的极细线为例。
[
{
"cpu": "${var.master_container_cpu}",
}
]
调用 aws_ecs_task_definition
资源时附加到此 tf 参数;
container_definitions = "${file("task-definitions/example.json")}"
会导致如下错误;
Error: aws_ecs_task_definition.example-task: ECS Task Definition container_definitions is invalid: Error decoding JSON: json: cannot unmarshal string into Go struct field ContainerDefinition.Cpu of type int64
欢迎任何帮助:)
看起来你应该在定义
中使用之前使用template来编译JSONdata "template_file" "task" {
template = "${file("${task-definitions/example.json")}"
vars {
cpu = "${var.master_container_cpu}"
}
}
在 JSON 文件中,您可以使用 ${cpu}
然后您就可以使用输出作为您的定义
container_definitions = "${data.template_file.task.rendered}"