Skip to content

Commit

Permalink
Adjusted count of NAT gateways to be dependent upon the number of AZs (
Browse files Browse the repository at this point in the history
…#44)

* Adjusted count of nat gateways to be dependent upon the number of AZs instead of the number of private subnets
  • Loading branch information
dyindude authored and antonbabenko committed May 18, 2017
1 parent 7ea768e commit 2cbc513
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ resource "aws_route" "private_nat_gateway" {
route_table_id = "${element(aws_route_table.private.*.id, count.index)}"
destination_cidr_block = "0.0.0.0/0"
nat_gateway_id = "${element(aws_nat_gateway.natgw.*.id, count.index)}"
count = "${length(var.private_subnets) * lookup(map(var.enable_nat_gateway, 1), "true", 0)}"
count = "${length(var.azs) * lookup(map(var.enable_nat_gateway, 1), "true", 0)}"
}

resource "aws_route_table" "private" {
vpc_id = "${aws_vpc.mod.id}"
propagating_vgws = ["${var.private_propagating_vgws}"]
count = "${length(var.private_subnets)}"
count = "${length(var.azs)}"
tags = "${merge(var.tags, map("Name", format("%s-rt-private-%s", var.name, element(var.azs, count.index))))}"
}

Expand Down Expand Up @@ -87,13 +87,13 @@ resource "aws_subnet" "public" {

resource "aws_eip" "nateip" {
vpc = true
count = "${length(var.private_subnets) * lookup(map(var.enable_nat_gateway, 1), "true", 0)}"
count = "${length(var.azs) * lookup(map(var.enable_nat_gateway, 1), "true", 0)}"
}

resource "aws_nat_gateway" "natgw" {
allocation_id = "${element(aws_eip.nateip.*.id, count.index)}"
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
count = "${length(var.private_subnets) * lookup(map(var.enable_nat_gateway, 1), "true", 0)}"
count = "${length(var.azs) * lookup(map(var.enable_nat_gateway, 1), "true", 0)}"

depends_on = ["aws_internet_gateway.mod"]
}
Expand Down

0 comments on commit 2cbc513

Please sign in to comment.