Skip to content

Commit 2d92a22

Browse files
authored
Fix public-only subnets (#162)
1 parent dd95ccd commit 2d92a22

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ Available targets:
357357
| <a name="input_label_value_case"></a> [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,<br>set as tag values, and output by this module individually.<br>Does not affect values of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation).<br>Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.<br>Default value: `lower`. | `string` | `null` | no |
358358
| <a name="input_labels_as_tags"></a> [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.<br>Default is to include all labels.<br>Tags with empty values will not be included in the `tags` output.<br>Set to `[]` to suppress all generated tags.<br>**Notes:**<br> The value of the `name` tag, if included, will be the `id`, not the `name`.<br> Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be<br> changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | <pre>[<br> "default"<br>]</pre> | no |
359359
| <a name="input_map_public_ip_on_launch"></a> [map\_public\_ip\_on\_launch](#input\_map\_public\_ip\_on\_launch) | If `true`, instances launched into a public subnet will be assigned a public IPv4 address | `bool` | `true` | no |
360-
| <a name="input_max_nats"></a> [max\_nats](#input\_max\_nats) | Maximum number of NAT Gateways or NAT instances to create | `number` | `999` | no |
360+
| <a name="input_max_nats"></a> [max\_nats](#input\_max\_nats) | Upper limit on number of NAT Gateways/Instances to create.<br>Set to 1 or 2 for cost savings at the expense of availability. | `number` | `999` | no |
361361
| <a name="input_max_subnet_count"></a> [max\_subnet\_count](#input\_max\_subnet\_count) | Sets the maximum number of each type (public or private) of subnet to deploy.<br>0 will reserve a CIDR for every Availability Zone (excluding Local Zones) in the region, and<br>deploy a subnet in each availability zone specified in `availability_zones` or `availability_zone_ids`,<br>or every zone if none are specified. We recommend setting this equal to the maximum number of AZs you anticipate using,<br>to avoid causing subnets to be destroyed and recreated with smaller IPv4 CIDRs when AWS adds an availability zone.<br>Due to Terraform limitations, you can not set `max_subnet_count` from a computed value, you have to set it<br>from an explicit constant. For most cases, `3` is a good choice. | `number` | `0` | no |
362362
| <a name="input_metadata_http_endpoint_enabled"></a> [metadata\_http\_endpoint\_enabled](#input\_metadata\_http\_endpoint\_enabled) | Whether the metadata service is available on the created NAT instances | `bool` | `true` | no |
363363
| <a name="input_metadata_http_put_response_hop_limit"></a> [metadata\_http\_put\_response\_hop\_limit](#input\_metadata\_http\_put\_response\_hop\_limit) | The desired HTTP PUT response hop limit (between 1 and 64) for instance metadata requests on the created NAT instances | `number` | `1` | no |

docs/terraform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
| <a name="input_label_value_case"></a> [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,<br>set as tag values, and output by this module individually.<br>Does not affect values of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation).<br>Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.<br>Default value: `lower`. | `string` | `null` | no |
9999
| <a name="input_labels_as_tags"></a> [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.<br>Default is to include all labels.<br>Tags with empty values will not be included in the `tags` output.<br>Set to `[]` to suppress all generated tags.<br>**Notes:**<br> The value of the `name` tag, if included, will be the `id`, not the `name`.<br> Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be<br> changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | <pre>[<br> "default"<br>]</pre> | no |
100100
| <a name="input_map_public_ip_on_launch"></a> [map\_public\_ip\_on\_launch](#input\_map\_public\_ip\_on\_launch) | If `true`, instances launched into a public subnet will be assigned a public IPv4 address | `bool` | `true` | no |
101-
| <a name="input_max_nats"></a> [max\_nats](#input\_max\_nats) | Maximum number of NAT Gateways or NAT instances to create | `number` | `999` | no |
101+
| <a name="input_max_nats"></a> [max\_nats](#input\_max\_nats) | Upper limit on number of NAT Gateways/Instances to create.<br>Set to 1 or 2 for cost savings at the expense of availability. | `number` | `999` | no |
102102
| <a name="input_max_subnet_count"></a> [max\_subnet\_count](#input\_max\_subnet\_count) | Sets the maximum number of each type (public or private) of subnet to deploy.<br>0 will reserve a CIDR for every Availability Zone (excluding Local Zones) in the region, and<br>deploy a subnet in each availability zone specified in `availability_zones` or `availability_zone_ids`,<br>or every zone if none are specified. We recommend setting this equal to the maximum number of AZs you anticipate using,<br>to avoid causing subnets to be destroyed and recreated with smaller IPv4 CIDRs when AWS adds an availability zone.<br>Due to Terraform limitations, you can not set `max_subnet_count` from a computed value, you have to set it<br>from an explicit constant. For most cases, `3` is a good choice. | `number` | `0` | no |
103103
| <a name="input_metadata_http_endpoint_enabled"></a> [metadata\_http\_endpoint\_enabled](#input\_metadata\_http\_endpoint\_enabled) | Whether the metadata service is available on the created NAT instances | `bool` | `true` | no |
104104
| <a name="input_metadata_http_put_response_hop_limit"></a> [metadata\_http\_put\_response\_hop\_limit](#input\_metadata\_http\_put\_response\_hop\_limit) | The desired HTTP PUT response hop limit (between 1 and 64) for instance metadata requests on the created NAT instances | `number` | `1` | no |

nat-gateway.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ resource "aws_nat_gateway" "default" {
2323
depends_on = [aws_eip_association.nat_instance]
2424
}
2525

26+
# If private IPv4 subnets and NAT Gateway are both enabled, create a
27+
# default route from private subnet to NAT Gateway in each subnet
2628
resource "aws_route" "nat4" {
2729
count = local.nat_gateway_enabled && local.private4_enabled ? local.private_route_table_count : 0
2830

@@ -37,6 +39,8 @@ resource "aws_route" "nat4" {
3739
}
3840
}
3941

42+
# If private IPv6 subnet needs NAT64 and NAT Gateway is enabled, create a
43+
# NAT64 route from private subnet to NAT Gateway in each subnet
4044
resource "aws_route" "private_nat64" {
4145
count = local.nat_gateway_enabled && local.private_dns64_enabled ? local.private_route_table_count : 0
4246

@@ -51,6 +55,8 @@ resource "aws_route" "private_nat64" {
5155
}
5256
}
5357

58+
# If public IPv6 subnet needs NAT64 and NAT Gateway is enabled, create a
59+
# NAT64 route from private subnet to NAT Gateway in each subnet
5460
resource "aws_route" "public_nat64" {
5561
count = local.nat_gateway_enabled && local.public_dns64_enabled ? local.public_route_table_count : 0
5662

nat-instance.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ resource "aws_eip_association" "nat_instance" {
124124
allocation_id = local.nat_eip_allocations[count.index]
125125
}
126126

127+
# If private IPv4 subnets and NAT Instance are both enabled, create a
128+
# default route from private subnet to NAT Instance in each subnet
127129
resource "aws_route" "nat_instance" {
128130
count = local.nat_instance_enabled ? local.private_route_table_count : 0
129131

public.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ resource "aws_subnet" "public" {
2121
# Use element()'s wrap-around behavior to handle the case where we are only provisioning public subnets.
2222
cidr_block = local.public4_enabled ? element(local.ipv4_public_subnet_cidrs, count.index) : null
2323
ipv6_cidr_block = local.public6_enabled ? element(local.ipv6_public_subnet_cidrs, count.index) : null
24-
ipv6_native = local.public6_enabled && !local.private4_enabled
24+
ipv6_native = local.public6_enabled && !local.public4_enabled
2525

2626
#bridgecrew:skip=BC_AWS_NETWORKING_53:Public VPCs should be allowed to default to public IPs
27-
map_public_ip_on_launch = local.private4_enabled ? var.map_public_ip_on_launch : null
27+
map_public_ip_on_launch = local.public4_enabled ? var.map_public_ip_on_launch : null
2828

2929
assign_ipv6_address_on_creation = local.public6_enabled ? var.public_assign_ipv6_address_on_creation : null
3030
enable_dns64 = local.public6_enabled ? local.public_dns64_enabled : null
3131

32-
enable_resource_name_dns_a_record_on_launch = local.private4_enabled ? var.ipv4_public_instance_hostnames_enabled : null
33-
enable_resource_name_dns_aaaa_record_on_launch = local.public6_enabled ? var.ipv6_public_instance_hostnames_enabled || !local.private4_enabled : null
32+
enable_resource_name_dns_a_record_on_launch = local.public4_enabled ? var.ipv4_public_instance_hostnames_enabled : null
33+
enable_resource_name_dns_aaaa_record_on_launch = local.public6_enabled ? var.ipv6_public_instance_hostnames_enabled || !local.public4_enabled : null
3434

35-
private_dns_hostname_type_on_launch = local.private4_enabled ? var.ipv4_public_instance_hostname_type : null
35+
private_dns_hostname_type_on_launch = local.public4_enabled ? var.ipv4_public_instance_hostname_type : null
3636

3737

3838
tags = merge(
@@ -62,7 +62,7 @@ resource "aws_route_table" "public" {
6262
}
6363

6464
resource "aws_route" "public" {
65-
count = local.private4_enabled && local.igw_configured ? local.public_route_table_count : 0
65+
count = local.public4_enabled && local.igw_configured ? local.public_route_table_count : 0
6666

6767
route_table_id = local.public_route_table_ids[count.index]
6868
destination_cidr_block = "0.0.0.0/0"
@@ -104,7 +104,7 @@ resource "aws_network_acl" "public" {
104104
}
105105

106106
resource "aws_network_acl_rule" "public4_ingress" {
107-
count = local.public_open_network_acl_enabled && local.private4_enabled ? 1 : 0
107+
count = local.public_open_network_acl_enabled && local.public4_enabled ? 1 : 0
108108

109109
network_acl_id = aws_network_acl.public[0].id
110110
rule_action = "allow"
@@ -118,7 +118,7 @@ resource "aws_network_acl_rule" "public4_ingress" {
118118
}
119119

120120
resource "aws_network_acl_rule" "public4_egress" {
121-
count = local.public_open_network_acl_enabled && local.private4_enabled ? 1 : 0
121+
count = local.public_open_network_acl_enabled && local.public4_enabled ? 1 : 0
122122

123123
network_acl_id = aws_network_acl.public[0].id
124124
rule_action = "allow"

variables.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ variable "max_subnet_count" {
4545

4646
variable "max_nats" {
4747
type = number
48-
description = "Maximum number of NAT Gateways or NAT instances to create"
48+
description = <<-EOT
49+
Upper limit on number of NAT Gateways/Instances to create.
50+
Set to 1 or 2 for cost savings at the expense of availability.
51+
EOT
4952
# Default should be MAX_INT, but Terraform does not provide that. 999 is big enough.
5053
default = 999
5154
}

0 commit comments

Comments
 (0)