1

I am creating a VPC via terraform - however i am facing some issues with subnnet association - which means - i have a private subnet across 3 AZ, abc.

it creates me 3 subnets however it does associate with it self only when i Check on routing table Explicitly Associated With itself only with with the 3 subnets, which are accross AZ?

any ideas ?

Subnets:

 variable "private_subnets" {
  description = "A list of private subnets inside the VPC."
  default     = ["10.31.100.0/22","10.31.104.0/22","10.31.108.0/22"]
}

#AWS routeing association:     
resource "aws_route_table_association" "private" {
  count          = "${length(var.private_subnets)}"
  subnet_id      = "${element(aws_subnet.private.*.id, count.index)}"
  route_table_id = "${element(aws_route_table.private.*.id, count.index)}"

 resource "aws_subnet" "private" {
  vpc_id            = "${aws_vpc.mod.id}"
  cidr_block        = "${var.private_subnets[count.index]}"
  availability_zone = "${var.azs[count.index]}"
  count             = "${length(var.private_subnets)}"

  tags {
    Name = "${var.name}-subnet-private-${element(var.azs, count.index)}"
  }
}

resource "aws_route_table" "private" {
 vpc_id           = "${aws_vpc.mod.id}"
 propagating_vgws = ["${var.private_propagating_vgws}"]
 count            = "${length(var.private_subnets)}"

  tags {
    Name = "${var.name}-rt-private-${element(var.azs, count.index)}"
  }
}

Outputs: 

   output "private_subnets" {
  value = ["${aws_subnet.private.*.id}"]
}

  variable "azs" {
  description = "A list of Availability zones in the region"
  default     = ["eu-west-1a","eu-west-1b","eu-west-1c"]
}
jordanm
  • 889
  • 5
  • 9
Jenna Shaik
  • 21
  • 1
  • 6
  • 1
    I don't understand your problem or question. Can you please edit your question to clarify. – Tim Jan 03 '17 at 20:10
  • Your question is not clear. Please describe what you are expecting to get as a result and what actually happens. If you simply need a new VPC you can use this module : https://github.com/terraform-community-modules/tf_aws_vpc This will create AWS recommended VPC layout. With 3 private and 3 public subnets spread across 3 AZs. – Andrey Jan 09 '17 at 17:35

0 Answers0