【发布时间】:2021-09-11 02:13:20
【问题描述】:
我正在构建一个 Fargate 集群,但在遵循 aws_ecs_task_definition 部分 (https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition) 的文档时遇到了困难
│ Error: ECS Task Definition container_definitions is invalid: Error decoding JSON: json: cannot unmarshal string into Go struct field ContainerDefinition.Cpu of type int64
│
│ with aws_ecs_task_definition.app,
│ on ecs.tf line 40, in resource "aws_ecs_task_definition" "app":
│ 40: container_definitions = jsonencode([
│ 41: {
│ 42: "name": "${var.prefix}",
│ 43: "image": "${var.app_image}",
│ 44: "cpu": "256",
│ 45: "memory": "${var.fargate_memory}",
│ 46: "networkMode": "awsvpc",
│ 47: "logConfiguration": {
│ 48: "logDriver": "awslogs",
│ 49: "options": {
│ 50: "awslogs-group": "${aws_cloudwatch_log_group.ecs.name}",
│ 51: "awslogs-region": "${var.region}",
│ 52: "awslogs-stream-prefix": "ecs"
│ 53: }
│ 54: },
│ 55: "environment": [
│ 56: {"name": "ENV_RUNNER_SLEEP_SECS", "value": "${var.app_env_runner_sleep_secs}"}
│ 57: ]
│ 58: }
│ 59: ])
错误指向 CPU 的值。这通常是另一个变量,但我只是在测试输入以尝试让它通过。烦人的是,如果我将值设置为一个数字,我会得到一个不同的错误:cannot unmarshal number into Go struct field KeyValuePair.Environment.Value of type string。
有什么想法吗?
【问题讨论】:
-
第二个错误来自另一个字段 - 数字对于 cpu 是正确的。
标签: json amazon-web-services terraform amazon-ecs unmarshalling