Skip to content

Commit

Permalink
terraform-community-modules#42 Add support for provisioning only a …
Browse files Browse the repository at this point in the history
…single NAT Gateway
  • Loading branch information
n8io committed Jul 23, 2017
1 parent e15fdbf commit ed802eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ resource "aws_subnet" "public" {

resource "aws_eip" "nateip" {
vpc = true
count = "${length(var.azs) * lookup(map("true", 1, "1", 1), var.enable_nat_gateway, 0)}"
count = "${(var.single_nat_gateway ? 1 : length(var.azs)) * lookup(map("true", 1, "1", 1), var.enable_nat_gateway, 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.azs) * lookup(map("true", 1, "1", 1), var.enable_nat_gateway, 0)}"
allocation_id = "${element(aws_eip.nateip.*.id, (var.single_nat_gateway ? 0 : count.index))}"
subnet_id = "${element(aws_subnet.public.*.id, (var.single_nat_gateway ? 0 : count.index))}"
count = "${(var.single_nat_gateway ? 1 : length(var.azs)) * lookup(map("true", 1, "1", 1), var.enable_nat_gateway, 0)}"

depends_on = ["aws_internet_gateway.mod"]
}
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ variable "enable_nat_gateway" {
default = false
}

variable "single_nat_gateway" {
description = "should be true if you want to provision a single shared NAT Gateway across all of your private networks"
default = false
}

variable "enable_s3_endpoint" {
description = "should be true if you want to provision an S3 endpoint to the VPC"
default = false
Expand Down

0 comments on commit ed802eb

Please sign in to comment.