title: Create AWS RDS instance in non default VPC using terraform
body: <p>I am using Terraform v0.10.2. I have created VPC in <i>modules/vpc/main.tf</i> and <i>modules/acl/main.tf</i>. I am accessing it using it's output.</p>
  
  <p>I can successfully create ec2 instance in public subnet in above vpc like so:</p>
  
  <pre><code>subnet_id = "${element(module.vpc.public_subnet_ids, count.index)}"
  </code></pre>
  
  <p>I want to add the RDS instance to private subnet. I tried what the terraform doc said:</p>
  
  <pre><code>vpc_security_group_ids    = [
    "${aws_security_group.db_access_sg.id}"
  ]
  db_subnet_group_name = "${module.vpc.aws_db_subnet_group_database}"
  </code></pre>
  
  <p>But, it is adding to the default VPC. If i put the subnet outside the module and access the resource, it gives the variable not found error.</p>
  
  <p>I have referred many GitHub examples, but without success. Am i missing something ?</p>
  
  <p>And this is one of the link i referred: <a href="https://github.com/hashicorp/terraform/issues/13739" rel="nofollow noreferrer">https://github.com/hashicorp/terraform/issues/13739</a></p>
  
  <p><b>Contents of modules/vpc/main.tf</b></p>
  
  <pre><code>resource "aws_vpc" "mod" {
    cidr_block = "${var.cidr}"
  
    tags {
      Name = "${var.name}"
    }
  }
  
  resource "aws_internet_gateway" "mod" {
    vpc_id = "${aws_vpc.mod.id}"
  }
  
  resource "aws_route_table" "public" {
    vpc_id           = "${aws_vpc.mod.id}"
    propagating_vgws = ["${compact(split(",", var.public_propagating_vgws))}"]
  
    tags {
      Name = "${var.name}-public"
    }
  }
  
  resource "aws_route" "public_internet_gateway" {
    route_table_id         = "${aws_route_table.public.id}"
    destination_cidr_block = "0.0.0.0/0"
    gateway_id             = "${aws_internet_gateway.mod.id}"
  }
  
  resource "aws_route_table" "private" {
    vpc_id           = "${aws_vpc.mod.id}"
    propagating_vgws = ["${compact(split(",", var.private_propagating_vgws))}"]
  
    tags {
      Name = "${var.name}-private"
    }
  }
  
  resource "aws_subnet" "private" {
    vpc_id            = "${aws_vpc.mod.id}"
    cidr_block        = "${element(split(",", var.private_subnets), count.index)}"
    availability_zone = "${element(split(",", var.azs), count.index)}"
    count             = "${length(compact(split(",", var.private_subnets)))}"
  
    tags {
      Name = "${var.name}-private"
    }
  }
  
  resource "aws_subnet" "public" {
    vpc_id            = "${aws_vpc.mod.id}"
    cidr_block        = "${element(split(",", var.public_subnets), count.index)}"
    availability_zone = "${element(split(",", var.azs), count.index)}"
    count             = "${length(compact(split(",", var.public_subnets)))}"
  
    tags {
      Name = "${var.name}-public"
    }
  
    map_public_ip_on_launch = true
  }
  
  resource "aws_db_subnet_group" "database" {
    name         = "${var.name}-rds-subnet-group-${count.index}"
    description  = "Database subnet groups for ${var.name}"
    subnet_ids   = ["${aws_subnet.private.*.id}"]
    #tags        = "${merge(var.tags, map("Name", format("%s-database-subnet-group", var.name)))}"
    count        = "${length(compact(split(",", var.private_subnets)))}"
  }
  
  resource "aws_route_table_association" "private" {
    count          = "${length(compact(split(",", var.private_subnets)))}"
    subnet_id      = "${element(aws_subnet.private.*.id, count.index)}"
    route_table_id = "${aws_route_table.private.id}"
  }
  
  resource "aws_route_table_association" "public" {
    count          = "${length(compact(split(",", var.public_subnets)))}"
    subnet_id      = "${element(aws_subnet.public.*.id, count.index)}"
    route_table_id = "${aws_route_table.public.id}"
  }
  </code></pre>
  
  <p><b>Contents of modules/vpc/outputs.tf</b></p>
  
  <pre><code>output "vpc_id" {
    value = "${aws_vpc.mod.id}"
  }
  
  output "public_subnet_ids" {
    value = ["${aws_subnet.public.*.id}"]
  }
  
  output "private_subnet_ids" {
    value = ["${aws_subnet.private.*.id}"]
  }
  
  output "aws_db_subnet_group_database" {
    value = "${aws_db_subnet_group.database.name}"
  }
  </code></pre>
  
  <p><b>Contents of modules/acl/main.tf</b></p>
  
  <pre><code>resource "aws_network_acl" "private_app_subnets" {
    vpc_id = "${var.vpc_id}"
  
    subnet_ids = ["${var.private_subnet_ids}"]
  }
  </code></pre>