Skip to content

Commit

Permalink
Fixing edge case when VPC is not symmetrical with few private subnets (
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbabenko authored Dec 11, 2017
1 parent 1f0e4fb commit d19812d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions examples/complete-vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,31 @@ module "vpc" {
tags = {
Owner = "user"
Environment = "staging"
Name = "complete"
}
}

# This example creates resources which are not present in all AZs.
# This should be seldomly needed from architectural point of view,
# and it can also lead this module to some edge cases.
module "not_symmetrical_vpc" {
source = "../../"

name = "not-symmetrical-example"

cidr = "10.0.0.0/16"

azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
private_subnets = ["10.0.1.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
database_subnets = ["10.0.21.0/24", "10.0.22.0/24", "10.0.23.0/24"]

create_database_subnet_group = true
enable_nat_gateway = true

tags = {
Terraform = "true"
Environment = "dev"
Name = "not-symmetrical"
}
}
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ resource "aws_nat_gateway" "this" {
}

resource "aws_route" "private_nat_gateway" {
count = "${var.enable_nat_gateway ? length(var.azs) : 0}"
count = "${var.enable_nat_gateway ? length(var.private_subnets) : 0}"

route_table_id = "${element(aws_route_table.private.*.id, count.index)}"
destination_cidr_block = "0.0.0.0/0"
Expand Down

0 comments on commit d19812d

Please sign in to comment.