title: How do you do simple string concatenation in Terraform?
body: <p>I must be being incredibly stupid but I can't figure out how to do simple string concatenation in Terraform.</p>
  
  <p>I have the following data <code>null_data_source</code>:</p>
  
  <pre><code>data "null_data_source" "api_gw_url" {
      inputs = {
        main_api_gw = "app.api.${var.env_name == "prod" ? "" : var.env_name}mydomain.com"
      }
  }
  </code></pre>
  
  <p>So when <code>env_name="prod"</code> I want the output <code>app.api.mydomain.com</code> and for anything else - let's say <code>env_name="staging"</code> I want <code>app.api.staging.mydomain.com</code>.</p>
  
  <p>But the above will output <code>app.api.stagingmydomain.com</code> &lt;-- notice the missing dot after <code>staging</code>.</p>
  
  <p>I tried concating the "." if the env_name was anything but "prod" but Terraform errors:</p>
  
  <pre><code>data "null_data_source" "api_gw_url" {
      inputs = {
        main_api_gw = "app.api.${var.env_name == "prod" ? "" : var.env_name + "."}mydomain.com"
      }
  }
  </code></pre>
  
  <p>The error is <code>__builtin_StringToInt: strconv.ParseInt: parsing ""</code></p>
  
  <p>The <a href="https://www.terraform.io/docs/configuration-0-11/interpolation.html#concat-list1-list2-" rel="noreferrer"><code>concat()</code></a> function in TF appears to be for lists not strings.</p>
  
  <p>So as the title says: <strong>How do you do simple string concatenation in Terraform?</strong></p>
  
  <p>I can't believe I'm asking how to concat 2 strings together XD</p>
  
  <p><strong>Update:</strong></p>
  
  <p>For anyone that has a similar issue I did this <em>horrific</em> workaround for the time being:</p>
  
  <p><code>main_api_gw = "app.api.${var.env_name == "prod" ? "" : var.env_name}${var.env_name == "prod" ? "" : "."}mydomain.com"</code></p>