title: Terraform dynamic variable
body: <p>I'm creating subnets as part of a seperate terraform template and exporting the IDs as follows.</p>
  
  <pre><code>output "subnet-aza-dev" {
    value = "${aws_subnet.subnet-aza-dev.id}"
  }
  output "subnet-azb-dev" {
    value = "${aws_subnet.subnet-azb-dev.id}"
  }
  output "subnet-aza-test" {
    value = "${aws_subnet.subnet-aza-test.id}"
  }
  output "subnet-azb-test" {
    value = "${aws_subnet.subnet-azb-test.id}"
  }
  ...
  </code></pre>
  
  <p>I'm then intending to lookup these IDs in another template which is reused to provision multiple environments. Example below shows my second template is calling a module to provision an EC2 instance and is passing through the subnet_id.</p>
  
  <pre><code>variable "environment" {
      description = "Environment name"
      default     = "dev"
  }
  
  module "sql-1-ec2" {
    source     = "../modules/ec2winserver_sql"
    ...
    subnet_id  = "${data.terraform_remote_state.env-shared.subnet-aza-dev}" 
  }
  </code></pre>
  
  <p>What I'd like to do is pass the environment variable as part of the lookup for the subnet_id e.g.</p>
  
  <pre><code>subnet_id  = "${data.terraform_remote_state.env-shared.subnet-aza-${var.environment}"
  </code></pre>
  
  <p>However I'm aware that variable interpolation isn't supported. I've tried using a map inside of the first terraform template to export them all to a 'subnet' which I could then use to lookup from the second template. This didn't work as I was unable to output variables inside of the map.</p>
  
  <p>This sort of design pattern is something I've used previously with CloudFormation, however I'm much newer to terraform. Am I missing something obvious here?</p>