title: Terraform: Passing JSON file as environment variable value with a systemd unit file inside docker container
body: <p>I am trying to pass json in an environmental variable of a systemd unit file with terraform. I am using an external provider named CT to generate ignition from the YAML configuration.</p>
  <p>CT Config:</p>
  <pre><code>data &quot;ct_config&quot; &quot;ignition&quot; {
    # Reference: https://github.com/poseidon/terraform-provider-ct/
    content      = data.template_file.bastion_user_data.rendered
    strict       = true
    pretty_print = false
  }
  </code></pre>
  <p>Error:</p>
  <pre><code>Error: error converting to Ignition: error at line 61, column 17
  invalid unit content: unexpected newline encountered while parsing option name
  
    on ../../modules/example/launch-template.tf line 91, in data &quot;ct_config&quot; &quot;ignition&quot;:
    91: data &quot;ct_config&quot; &quot;ignition&quot; {
  </code></pre>
  <p>Unit File Content:</p>
  <pre><code>- name: cw-agent.service
    enabled: true
    contents: |
      [Unit]
      Description=Cloudwatch Agent Service
      Documentation=https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html
      Requires=docker.socket
      After=docker.socket
      [Service]
      TimeoutStartSec=0
      Restart=always
      RestartSec=10s
      Environment=CONFIG=${cw-agent-config}
      ExecStartPre=-/usr/bin/docker kill cloudwatch-agent
      ExecStartPre=-/usr/bin/docker rm cloudwatch-agent
      ExecStartPre=/usr/bin/docker pull amazon/cloudwatch-agent
      ExecStart=/usr/bin/docker run --name cloudwatch-agent \
                                --net host \
                                --env CW_CONFIG_CONTENT=$CONFIG \
                                amazon/cloudwatch-agent
      ExecStop=/usr/bin/docker stop cloudwatch-agent
      [Install]
      WantedBy=multi-user.target
  </code></pre>
  <p>Rendering:</p>
  <pre><code>data &quot;template_file&quot; &quot;cw_agent_config&quot; {
    template = file(&quot;${path.module}/../cw-agent-config.json&quot;)
  }
  
  cw-agent-config = indent(10, data.template_file.cw_agent_config.rendered)
  </code></pre>
  <p>File Content:</p>
  <pre><code>{
      &quot;agent&quot;: {
          &quot;metrics_collection_interval&quot;: 60,
  &quot;run_as_user&quot;: &quot;cwagent&quot;
      },
      &quot;metrics&quot;: {
          &quot;append_dimensions&quot;: {
              &quot;AutoScalingGroupName&quot;: &quot;$${aws:AutoScalingGroupName}&quot;,
              &quot;ImageId&quot;: &quot;$${aws:ImageId}&quot;,
              &quot;InstanceId&quot;: &quot;$${aws:InstanceId}&quot;,
              &quot;InstanceType&quot;: &quot;$${aws:InstanceType}&quot;
          },
          &quot;metrics_collected&quot;: {
              &quot;disk&quot;: {
                  &quot;drop_device&quot; : true,
                  &quot;measurement&quot;: [
                      &quot;used_percent&quot;
                  ],
                  &quot;metrics_collection_interval&quot;: 120,
                  &quot;resources&quot;: [
                      &quot;/&quot;
                  ]
              },
              &quot;mem&quot;: {
                  &quot;measurement&quot;: [
                      &quot;mem_used_percent&quot;
                  ],
                  &quot;metrics_collection_interval&quot;: 120
              }
          }
      }
  }
  </code></pre>
  <p>I need this json file to be available as a value of environment variable named <code>CW_CONFIG_CONTENT</code> inside a docker container.</p>