Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data/aws: create fewer NAT gateways #1450

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion data/data/aws/vpc/vpc-private.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ resource "aws_route" "to_nat_gw" {
count = "${local.new_az_count}"
route_table_id = "${aws_route_table.private_routes.*.id[count.index]}"
destination_cidr_block = "0.0.0.0/0"
nat_gateway_id = "${element(aws_nat_gateway.nat_gw.*.id, count.index)}"
nat_gateway_id = "${element(aws_nat_gateway.nat_gw.*.id, count.index % length(aws_nat_gateway.nat_gw.*.id))}"
depends_on = ["aws_route_table.private_routes"]
}

Expand All @@ -35,3 +35,13 @@ resource "aws_route_table_association" "private_routing" {
route_table_id = "${aws_route_table.private_routes.*.id[count.index]}"
subnet_id = "${aws_subnet.private_subnet.*.id[count.index]}"
}

resource "aws_nat_gateway" "nat_gw" {
count = "${min(local.new_az_count, 3)}"
allocation_id = "${aws_eip.nat_eip.*.id[count.index]}"
subnet_id = "${aws_subnet.public_subnet.*.id[count.index]}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why move these public-subnet resources into vpc-private.tf?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because they are private subnet resources, not public. the move should happen irrespective of this PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because they are private subnet resources, not public...

Ah, because while this resource lives in the public subnet, its purpose is to service instances in the private subnets.

the move should happen irrespective of this PR

Personally I'd rather collapse vpc-private.tf and vpc-public.tf together. The unified file would only be ~100 lines. I'd work up a PR, but there are other PRs in flight touching this code and I don't think we could get this file-rename landed before the coming freeze.


tags = "${merge(map(
"Name", "${var.cluster_id}-nat-${local.new_subnet_azs[count.index]}",
), var.tags)}"
}
10 changes: 0 additions & 10 deletions data/data/aws/vpc/vpc-public.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,3 @@ resource "aws_eip" "nat_eip" {
# https://github.com/coreos/tectonic-installer/issues/1017#issuecomment-307780549
depends_on = ["aws_internet_gateway.igw"]
}

resource "aws_nat_gateway" "nat_gw" {
count = "${local.new_az_count}"
allocation_id = "${aws_eip.nat_eip.*.id[count.index]}"
subnet_id = "${aws_subnet.public_subnet.*.id[count.index]}"

tags = "${merge(map(
"Name", "${var.cluster_id}-nat-${local.new_subnet_azs[count.index]}",
), var.tags)}"
}