title: Terraform: Pass only a variable which was used, to a template file
body: <p>I need to render a template depending on a which variable (from a set of always existing, pre-defined variables) ends up being used when the resource is being called.</p>
  <p>Examples:</p>
  <p>variables.tf</p>
  <pre><code>possible_choice    = &quot;this&quot; 
  another_choice     = &quot;that&quot;
  yet_another_choice = &quot;then&quot;
  </code></pre>
  <p>main.tf</p>
  <pre><code>resource &quot;instance&quot; &quot;this_name&quot; {
  image_id = var.possible_choice
  user_data   = templatefile( &quot;my_template_file.tpl&quot;, {choice = image_id})
  }
  </code></pre>
  <p>template file:</p>
  <pre><code>%{ if choice == ....) %{endif}
  </code></pre>
  <p>What I cannot accomplish is passing the value of the variable which was chosen to be implemneted in the resource.</p>
  <ul>
  <li><p>I can't check if a variable is null (because they are all defined in variables.tf and will return a string).</p>
  </li>
  <li><p>I can't pass <code>instance.this_name</code> because the naming is not uniform (it could be either of <code>this_name.possible_choice</code> and so on).</p>
  </li>
  </ul>
  <p>If could extract whichever default value is contained within <code>instance.this_name.image_id</code>, then I should be good to go, I'd assume. I've tried multiple ways but mostly got <code>cannot refer to itself</code>, which makes sense.</p>
  <p>Thank you.</p>