title: How do I manage three (per-environment) user data files in terraform?
body: <p>I have three specific user-data files for three different environments. Based on user input on the <code>env</code> (environment) variable, we have to pick either one of the user data files for <code>aws_instance</code> terraform resource. </p>
  
  <pre><code>variable "env" {
     description = "choose env between dev | prod | qa "
  }
  </code></pre>
  
  <p>Here are the three user data files:</p>
  
  <ol>
  <li><h2><code>user_data_dev.sh</code>:</h2>
  
  <pre class="lang-sh prettyprint-override"><code>#!/bin/bash
  DOMAIN = "testing.dev.xxxx.com"
  PORT = "8080"
  </code></pre></li>
  <li><h2><code>user_data_prod.sh</code></h2>
  
  <pre class="lang-sh prettyprint-override"><code>#!/bin/bash
  DOMAIN = "testing.prod.xxxx.com"
  PORT = "8080"
  </code></pre></li>
  <li><h2><code>user_data_qa.sh</code></h2>
  
  <pre class="lang-sh prettyprint-override"><code>#!/bin/bash
  DOMAIN = "testing.qa.xxxx.com"
  PORT = "8080"
  
  resource "aws_instance" "server" {
    ami = "ami-123456"
    instance_type = "t2.medium"
    availability_zone = "us-east-1"
    user_data = "${template_file.user_data_graphite.rendered}"
    root_block_device {
      delete_on_termination = true
      volume_size = "${var.volume_size}"
      volume_type = "${var.volume_type}"
    }
    tags {
      Name = "domain_testing"
  }
  </code></pre></li>
  </ol>