title: Dynamic Packer Variables Name
body: <p>Use-Case is to use PACKER variable file to build AWS AMI in &quot;us-east-1&quot; and &quot;us-east-2&quot; region. I can have two separate file for NV and OH region. But I am trying out if that can be done using same variable file.</p>
  <p>Based on the value of variable '<strong>PACKER_BUILD_REGION</strong>' in <strong>Packer_Var_File.json</strong> file, my packer build should select the value specific to NV or OH region only. Any suggestion how to achieve this?</p>
  <p>Packer Build Command: <strong><code>packer build -var-file Packer_Var_File.json Packer_Build_File.json</code></strong></p>
  <p>Detail of <strong>Packer_Var_File.json</strong> file as given below</p>
  <pre><code>{
      &quot;PACKER_BUILD_REGION&quot;: &quot;NV&quot;,
  
      &quot;1&quot;: &quot;This Section to defined 'North Verginia' REGION SPECIFIC Varianles for AMI Build&quot;, 
      &quot;!&quot;: &quot;================================================================================&quot;, 
      &quot;NV_region&quot;: &quot;us-east-1&quot;,
      &quot;NV_vpc_id&quot;: &quot;vpc-00112233&quot;,
      &quot;NV_subnet_id&quot;: &quot;subnet-001122334455&quot;,
      &quot;NV_ssh_keypair_name&quot;: &quot;NV_SSH_KEY&quot;,
      &quot;NV_ssh_private_key_file&quot;: &quot;{{user `NV_ssh_keypair_name`}}.pem&quot;, 
      &quot;NV_security_group_ids&quot;: &quot;sg-0101010,sg-0202020,sg-03030303&quot;,
  
      &quot;2&quot;: &quot;This Section to defined 'OHIO' REGION SPECIFIC Varianles for AMI Build&quot;, 
      &quot;@&quot;: &quot;======================================================================&quot;, 
      &quot;OH_region&quot;: &quot;us-east-2&quot;,
      &quot;OH_vpc_id&quot;: &quot;vpc-33221100&quot;,
      &quot;OH_subnet_id&quot;: &quot;subnet-554433221100&quot;,
      &quot;OH_ssh_keypair_name&quot;: &quot;OH_SSH_KEY&quot;,
      &quot;OH_ssh_private_key_file&quot;: &quot;{{user `OH_ssh_keypair_name`}}.pem&quot;, 
      &quot;OH_security_group_ids&quot;: &quot;sg-121314,sg-131517&quot;,
  
      &quot;3&quot;: &quot;This Section to defined all COMMON Varianles for AMI Build&quot;, 
      &quot;#&quot;: &quot;==========================================================&quot;, 
      &quot;KEY_region&quot;:               &quot;{{user `PACKER_BUILD_REGION`}}_region&quot;,
      &quot;KEY_vpc_id&quot;:               &quot;{{user `PACKER_BUILD_REGION`}}_vpc_id&quot;,
      &quot;KEY_subnet_id&quot;:            &quot;{{user `PACKER_BUILD_REGION`}}_subnet_id&quot;,
      &quot;KEY_source_ami&quot;:           &quot;{{user `PACKER_BUILD_REGION`}}_source_ami&quot;,
      &quot;KEY_ssh_keypair_name&quot;:     &quot;{{user `PACKER_BUILD_REGION`}}_ssh_keypair_name&quot;,
      &quot;KEY_ssh_private_key_file&quot;: &quot;{{user `PACKER_BUILD_REGION`}}_ssh_private_key_file&quot;,
      &quot;KEY_security_group_ids&quot;:   &quot;{{user `PACKER_BUILD_REGION`}}_security_group_ids&quot;,
      
      &quot;region&quot;: &quot;{{ user `KEY_region` }}&quot;,
      &quot;vpc_id&quot;: &quot;{{user `KEY_vpc_id` }}&quot;,
      &quot;subnet_id&quot;: &quot;{{user `KEY_subnet_id` }}&quot;,
      &quot;ssh_keypair_name&quot;: &quot;{{user `KEY_ssh_keypair_name` }}&quot;,
      &quot;ssh_private_key_file&quot;: &quot;.\\{{user `KEY_ssh_private_key_file`}}&quot;,
      &quot;security_group_ids&quot;: &quot;{{user `KEY_security_group_ids` }}&quot;,
      
      &quot;aws_access_key&quot;: &quot;{{env `AWS_ACCESS_KEY_ID`}}&quot;,
      &quot;aws_secret_key&quot;: &quot;{{env `AWS_SECRET_ACCESS_KEY`}}&quot;,
      &quot;instance_type&quot;: &quot;t3.large&quot;,
      &quot;iam_profile_name&quot;: &quot;Agent_iam_Access&quot;,
      &quot;ami_description&quot;: &quot;AMI on Windows Server 2019 with JDK 1.8.0_251, Chrome Driver 83.0.3987.106, Chrome Browser 83.0.3987.149, and Selenium 3.7.1 Jar&quot;,
      &quot;ami_regions&quot;: &quot;us-east-1,us-east-2&quot;,
      &quot;ami_users&quot;: &quot;01223334444,43322211110&quot;
  }
  
  </code></pre>