title: How to use Bash Commands in Terraform Template File Variables?
body: <p>I am using Terraform to configure an Auto Scaling Gitlab Runner. I am having issues when overwriting the runner configuration file (for which I am using Terraform Templates), because the file requires the Runner's Unique Token which is generated after registration.</p>
  
  <p>The configuration file looks like this: </p>
  
  <pre><code>concurrent = 1
  check_interval = 60
  
  [[runners]]
      name = "POC Group Runner"
      url = "https://gitlab.com/"
      token = "ABCD"
      executor = "docker+machine"
      limit = 1 # max number of docker machines to be created
  
  </code></pre>
  
  <p>I want to read this runner token (which is "ABCD") from this file, so that I can use it in a Terraform Template to overwrite the configurations.</p>
  
  <p>In terraform the only "read" function I have is "file", which reads the whole content, and then getting only the token from it becomes a ugly process: </p>
  
  <pre><code>trimspace(replace(split("executor", split("token =", file("/etc/gitlab-runner/config.toml"))[1])[0], "\"", ""))
  </code></pre>
  
  <p>Is it possible to use Bash Scripts to create variables for templates? </p>
  
  <p>For example I could use the following command to read the token:</p>
  
  <pre><code>cat /etc/gitlab-runner/config.toml | grep "token =" | awk '//{print $3}' | sed 's/"//g'
  </code></pre>
  
  <p>But how do I feed that into a template?</p>
  
  <p>Can I do something like this? :</p>
  
  <pre><code>Data "template_file" "runner-config" {
      template = "${file("runner-config.toml")"
      vars = {
          runner_token = "`cat /etc/gitlab-runner/config.toml | grep "token =" | awk '//{print $3}' | sed 's/"//g'`"
      }
  </code></pre>
  
  <p>Does anyone have either a better way of reading something specific from a file, or know how to use bash scripts in templates?</p>