JSON decoding error, invalid character '0' after upgrading from 0.11.15 to 0.12.0

terraform apply “terraform.tfplan”

aws_ecs_task_definition.nginx: Creating…

Error: Error decoding JSON: invalid character ‘0’ after object key:value pair

on main.tf line 151, in resource “aws_ecs_task_definition” “nginx”:
151: resource “aws_ecs_task_definition” “nginx” {

When I run terraform apply (see above), I get some kind of a JSON parsing error. This worked fine in 0.11.15, but when I upgraded to 0.12.0 I am getting this error now.

My relevant terraform code is below, is there anything that stands out that is causing this error?

What is the best way to debug this?


main.tf

 data "template_file" "nginx" {
    template = file("task-definitions/nginx.json")

    vars = {
      cpu         = var.nginx_fargate_cpu
      image       = "${module.repository_nginx.repository_url}:${var.image_tag}"
      memory      = var.nginx_fargate_memory
      log_group   = "log${var.project}Nginx"
      aws_region  = var.aws_region
      project     = var.project
      environment = var.environment
    }
  }

  resource "aws_ecs_task_definition" "nginx" {
    family                   = "${var.project}Nginx"
    network_mode             = "awsvpc"
    requires_compatibilities = ["FARGATE"]
    cpu                      = var.nginx_fargate_cpu
    memory                   = var.nginx_fargate_memory

    execution_role_arn = aws_iam_role.ecs_task_execution_role.arn

    container_definitions = data.template_file.nginx.rendered
  }

The JSON for this task is:

[
    {
      "name": "nginx",
      "image": "${image}",
      "cpu": ${cpu},
      "memory": ${memory},
      "portMappings": [
        {
          "containerPort": 8080
        }
      ],
      "logConfiguration": {
          "logDriver": "awslogs",
          "options": {
              "awslogs-group": "${log_group}",
              "awslogs-region": "${aws_region}",
              "awslogs-stream-prefix": "nginx"
          }
      }
    }
  ]

Hard to reproduce entirely without some of the values you’re passing in, not sure if quoting the vars (like ${cpu}) in the template file matters. High level, seems like something it’s expecting to be a string is starting with an unquoted 0, but could be wrong there.

Probably a good idea to migrate to templatefile() if you can, which it looks like has existed since 0.12, so may be worth just taking your lumps with that now and switching over. If you do a web search, there’s information and examples on how to switch over.