title: What is the best way to pass variables to a json using Terraform
body: <p>I have a simple <code>terraform</code> module that us using a <code>json</code> file as below:</p>
  <pre><code>resource &quot;aws_ecs_task_definition&quot; &quot;ecs_task_definition&quot; {
    container_definitions    = file(var.CONTAINER_DEFINITION_PATH)
    cpu                      = var.TASK_CPU
    execution_role_arn       = var.EXECUTION_ROLE_ARN
    family                   = var.TASK_FAMILY
    memory                   = var.TASK_MEMORY
    network_mode             = var.TASK_NETWORK_MODE
    requires_compatibilities = var.TASK_REQUIRES_COMPATABILITIES
  
    tags = var.TASK_TAGS
  
    task_role_arn = var.EXECUTION_ROLE_ARN
  }
  </code></pre>
  <p>And I am using this module as below:</p>
  <p><code>main.tf</code></p>
  <pre><code>module &quot;agent_connect_service_ecs_task_definition&quot; {
    source = &quot;./modules/task_definition&quot;
  
    CONTAINER_DEFINITION_PATH     = &quot;./container_definitions/agent_connect_service.json&quot;
    TASK_CPU                      = &quot;256&quot;
    EXECUTION_ROLE_ARN            = data.aws_iam_role.ecsTaskExecutionRole.arn
    TASK_FAMILY                   = var.AGENT_CONNECT_SERVICE_SERVICE_NAME // change me
    TASK_MEMORY                   = &quot;512&quot;
    TASK_NETWORK_MODE             = &quot;awsvpc&quot;
    TASK_REQUIRES_COMPATABILITIES = [&quot;FARGATE&quot;]
    TASK_TAGS                     = { &quot;Name&quot; : &quot;mlb-agent-connect&quot;, &quot;Project&quot; : &quot;mlb&quot;  } // change me
  }
  </code></pre>
  <p>And here in the json <code>agent_connect_service.json</code> I need to dynamically change some values. I have given below <strong>only</strong> a part of the json object for your readability where I need to have the dynamically changing value:</p>
  <pre><code>[
      {
          &quot;cpu&quot;: 0,
          &quot;environment&quot;: [
              {
                  &quot;name&quot;: &quot;ASPNETCORE_ENVIRONMENT&quot;,
                  &quot;value&quot;: &quot;&lt;VALUE-I-NEED-TO-CHANGE-DYNAMICALLY&gt;&quot;
              }
          ]
          .
          .
          .
      }
  ]
  </code></pre>
  <p>In the above json, how can I pass some random values to the <code>VALUE-I-NEED-TO-CHANGE-DYNAMICALLY</code> section? What is the best possible way I can get this done without really cluttering up the <code>main.tf</code> (means, I don't need to define the json file within the <code>main.tf</code> because I need that json definition in a different directory as it is now)</p>
  <p>Thank you</p>