title: Terraform: How to associate multiple subnet to route table?
body: <p>I'm using terraform v.0.11.7.</p>
  
  <p>I wants to create 4 subnets (2 public subnets, 2 private subnets)</p>
  
  <p>Here's a content of vars.tf</p>
  
  <pre><code>variable "region" {
    default = "ap-south-1"
  }
  
  variable "ami_id" {
    type = "map"
    default = "ami-d783a9b8"
  }
  
  variable "credentials" {
    default = "/root/.aws/credentials"
  }
  
  variable "vpc_cidr" {
    default = "10.0.0.0/16"
  }
  
  variable "pub_subnet_aza_cidr" {
    default = "10.0.10.0/24"
  }
  
  variable "pub_subnet_azc_cidr" {
    default = "10.0.20.0/24"
  }
  
  variable "pri_subnet_aza_cidr" {
    default = "10.0.30.0/24"
  }
  
  variable "pri_subnet_azc_cidr" {
    default = "10.0.40.0/24"
  }
  </code></pre>
  
  <p>Now inside main.tf, i want to associate the first 2 public subnets to public route table, how to do that?</p>
  
  <pre><code>resource "aws_subnet" "pub_subnet_aza" {
    vpc_cidr = "{aws_vpc.vpc.id}"
    cidr_block = "${var.pub_subnet_aza_cidr}"
    tags {
      Name = "Pub-Sunet-A"
   }
    availability_zone = "${data.aws_availability_zone.available.name[0]}"
  }
  
  resource "aws_subnet" "pub_subnet_azc" {
    vpc_cidr = "{aws_vpc.vpc.id}"
    cidr_block = "${var.pub_subnet_azc_cidr}"
    tags {
     Name = "Pub-Subnet-C"
  }
    availability_zone = "${data.aws_availability_zone.available.name[2]}"
  }
  
  resource "aws_route_table_association" "public" {
    subnet_id = "${aws_subnet.pub_subnet_aza.id}"  # How to put pub_subnet_azc.id into here?
    route_table_id = "${aws_route_table.public.id}"
  }
  </code></pre>