Error: ECS Task Definition container_definitions is invalid: Error decoding JSON: invalid character 'f' after object

Hi,
I have the following map object variable that I want to set as env variable in the ecs container.
In terraform console, I was able to successfully jsonencode and jsondecode this object and can’t figure out why it’s not being correctly decoded for use in the container definition. A terraform plan with just the default value of that variable fails with the JSON decode error in the title. I’m using AwS provider v4.67.0.

Any help in getting this working is much appreciated!

variable "data_filters_map" {
  description = "Map of data filters"
  default = {
    filter_type_one = {
      dataset = "example_dataset_one"
      version = "v1.0.0"
    }
    filter_type_two = {
      dataset = "example_dataset_two"
      version = "v2.1.0"
    }
    filter_type_three = {
      dataset = "example_dataset_three"
      version = "v3.5"
    }
  }
}

This is passed to the container definition template:

    filters_config = jsonencode(var.data_filters_map)

And used in the template:

      {
        "name": "FILTERS_CONFIG",
        "value": "${filters_config}"
      }

@solomon-negusse It’s difficult to fully understand the problem without the full configuration and container definition. You may want to provide it.

But based on the info you provided, I am guessing that filters_config is a local value, and you are passing that into the template as an environment using the container_definitions argument of the aws_ecs_task_definition resource. I would guess that it might be some encoding or escaping issue as described in the aws_ecs_task_defintion resource.

Perhaps you can check what’s passed to the API by enable TF debug logging, or look at the associated CloudTrail event.