Skip to content

Commit

Permalink
#42 Add support for provisioning only a single NAT Gateway (#58)
Browse files Browse the repository at this point in the history
* 🐛 #47  Fix issue with string vs bool value with enable_nat_gateway input

* ✨ #42 Add support for provisioning only a single NAT Gateway
  • Loading branch information
n8io authored and antonbabenko committed Aug 2, 2017
1 parent c82a16d commit 7a735de
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Module Input Variables
- `enable_dns_hostnames` - should be true if you want to use private DNS within the VPC
- `enable_dns_support` - should be true if you want to use private DNS within the VPC
- `enable_nat_gateway` - should be true if you want to provision NAT Gateways
- `single_nat_gateway` - should be true if you want to provision a single shared NAT Gateway across all of your private networks
- `enable_s3_endpoint` - should be true if you want to provision an S3 endpoint within the VPC
- `map_public_ip_on_launch` - should be false if you do not want to auto-assign public IP on launch
- `private_propagating_vgws` - list of VGWs the private route table should propagate
Expand Down
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 = "${var.enable_nat_gateway ? length(var.azs) : 0}"
count = "${var.enable_nat_gateway ? (var.single_nat_gateway ? 1 : length(var.azs)) : 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 = "${var.enable_nat_gateway ? length(var.azs) : 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.enable_nat_gateway ? (var.single_nat_gateway ? 1 : length(var.azs)) : 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 7a735de

Please sign in to comment.