Skip to content

Commit 4a65b30

Browse files
authored
Merge pull request #72 from aws-ia/connect-topublic-natgw
change variable parameter name of `route_to_nat` to `connect_to_public_natgw`
2 parents f245a1e + bd5e5b5 commit 4a65b30

File tree

10 files changed

+30
-29
lines changed

10 files changed

+30
-29
lines changed

.header.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module "vpc" {
2828
# omitting name_prefix defaults value to "private"
2929
# name_prefix = "private_with_egress"
3030
netmask = 24
31-
route_to_nat = "0.0.0.0/0"
31+
connect_to_public_natgw = true
3232
}
3333
}
3434
@@ -56,7 +56,7 @@ subnets = {
5656
# omitting name_prefix defaults value to "private"
5757
# name_prefix = "private"
5858
netmask = 24
59-
route_to_nat = "0.0.0.0/0"
59+
connect_to_public_natgw = true
6060
}
6161
6262
# can be any valid key name

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module "vpc" {
2929
# omitting name_prefix defaults value to "private"
3030
# name_prefix = "private_with_egress"
3131
netmask = 24
32-
route_to_nat = "0.0.0.0/0"
32+
connect_to_public_natgw = true
3333
}
3434
}
3535
@@ -57,7 +57,7 @@ subnets = {
5757
# omitting name_prefix defaults value to "private"
5858
# name_prefix = "private"
5959
netmask = 24
60-
route_to_nat = "0.0.0.0/0"
60+
connect_to_public_natgw = true
6161
}
6262
6363
# can be any valid key name
@@ -236,7 +236,7 @@ Please see our [developer documentation](https://github.com/aws-ia/terraform-aws
236236
|------|-------------|------|---------|:--------:|
237237
| <a name="input_az_count"></a> [az\_count](#input\_az\_count) | Searches region for # of AZs to use and takes a slice based on count. Assume slice is sorted a-z. | `number` | n/a | yes |
238238
| <a name="input_name"></a> [name](#input\_name) | Name to give VPC. Note: does not effect subnet names, which get assigned name based on name\_prefix. | `string` | n/a | yes |
239-
| <a name="input_subnets"></a> [subnets](#input\_subnets) | Configuration of subnets to build in VPC. 1 Subnet per AZ is created. Subnet types are defined as maps with the available keys: "private", "public", "transit\_gateway". Each Subnet type offers its own set of available arguments detailed below.<br><br>**Attributes shared across subnet types:**<br>- `cidrs` = (Optional\|list(string)) **Cannot set if `netmask` is set.** List of CIDRs to set to subnets. Count of CIDRs defined must match quatity of azs in `az_count`.<br>- `netmask` = (Optional\|Int) Netmask of the `var.cidr_block` to calculate for each subnet. **Cannot set if `cidrs` is set.**<br>- `name_prefix` = (Optional\|String) A string prefix to use for the name of your subnet and associated resources. Subnet type key name is used if omitted (aka private, public, transit\_gateway). Example `name_prefix = "private"` for `var.subnets.private` is redundant.<br>- `tags` = (Optional\|map(string)) Tags to set on the subnet and associated resources.<br><br>**Any private subnet type options:**<br>- All shared keys above<br>- `route_to_nat` = (Optional\|string) Determines if routes to NAT Gateways should be created. Specify the CIDR range or a prefix-list-id that you want routed to nat gateway. Usually `0.0.0.0/0`. Must also set `var.subnets.public.nat_gateway_configuration`.<br>- `route_to_transit_gateway` = (Optional\|string) Optionally create routes from private subnets to transit gateway subnets. Specify the CIDR range or a prefix-list-id that you want routed to the transit gateway.<br><br>**public subnet type options:**<br>- All shared keys above<br>- `nat_gateway_configuration` = (Optional\|string) Determines if NAT Gateways should be created and in how many AZs. Valid values = `"none"`, `"single_az"`, `"all_azs"`. Default = "none". Must also set `var.subnets.private.route_to_nat = true`.<br>- `route_to_transit_gateway` = (Optional\|string) Optionally create routes from public subnets to transit gateway subnets. Specify the CIDR range or a prefix-list-id that you want routed to the transit gateway.<br><br>**transit\_gateway subnet type options:**<br>- All shared keys above<br>- `route_to_nat` = (Optional\|string) Determines if routes to NAT Gateways should be created. Specify the CIDR range or a prefix-list-id that you want routed to nat gateway. Usually `0.0.0.0/0`. Must also set `var.subnets.public.nat_gateway_configuration`.<br>- `transit_gateway_id` = (Required\|string) Transit gateway to attach VPC to.<br>- `transit_gateway_default_route_table_association` = (Optional\|bool) Boolean whether the VPC Attachment should be associated with the EC2 Transit Gateway association default route table. This cannot be configured or perform drift detection with Resource Access Manager shared EC2 Transit Gateways.<br>- `transit_gateway_default_route_table_propagation` = (Optional\|bool) Boolean whether the VPC Attachment should propagate routes with the EC2 Transit Gateway propagation default route table. This cannot be configured or perform drift detection with Resource Access Manager shared EC2 Transit Gateways.<br>- `transit_gateway_appliance_mode_support` = (Optional\|string) Whether Appliance Mode is enabled. If enabled, a traffic flow between a source and a destination uses the same Availability Zone for the VPC attachment for the lifetime of that flow. Valid values: `disable` (default) and `enable`.<br>- `transit_gateway_dns_support` = (Optional\|string) DNS Support is used if you need the VPC to resolve public IPv4 DNS host names to private IPv4 addresses when queried from instances in another VPC attached to the transit gateway. Valid values: `enable` (default) and `disable`.<br><br>Example:<pre>subnets = {<br> public = {<br> netmask = 24<br> nat_gateway_configuration = "single_az"<br> route_to_transit_gateway = "10.1.0.0/16"<br> }<br><br> private = {<br> netmask = 24<br> route_to_nat = "0.0.0.0/0"<br> route_to_transit_gateway = "10.1.0.0/16"<br> }<br><br> transit_gateway = {<br> netmask = 24<br> transit_gateway_id = aws_ec2_transit_gateway.example.id<br> route_to_nat = "0.0.0.0/0"<br> transit_gateway_default_route_table_association = true<br> transit_gateway_default_route_table_propagation = true<br> }<br>}</pre> | `any` | n/a | yes |
239+
| <a name="input_subnets"></a> [subnets](#input\_subnets) | Configuration of subnets to build in VPC. 1 Subnet per AZ is created. Subnet types are defined as maps with the available keys: "private", "public", "transit\_gateway". Each Subnet type offers its own set of available arguments detailed below.<br><br>**Attributes shared across subnet types:**<br>- `cidrs` = (Optional\|list(string)) **Cannot set if `netmask` is set.** List of CIDRs to set to subnets. Count of CIDRs defined must match quatity of azs in `az_count`.<br>- `netmask` = (Optional\|Int) Netmask of the `var.cidr_block` to calculate for each subnet. **Cannot set if `cidrs` is set.**<br>- `name_prefix` = (Optional\|String) A string prefix to use for the name of your subnet and associated resources. Subnet type key name is used if omitted (aka private, public, transit\_gateway). Example `name_prefix = "private"` for `var.subnets.private` is redundant.<br>- `tags` = (Optional\|map(string)) Tags to set on the subnet and associated resources.<br><br>**Any private subnet type options:**<br>- All shared keys above<br>- `connect_to_public_natgw` = (Optional\|string) Determines if routes to NAT Gateways should be created. Specify the CIDR range or a prefix-list-id that you want routed to nat gateway. Usually `0.0.0.0/0`. Must also set `var.subnets.public.nat_gateway_configuration`.<br>- `route_to_transit_gateway` = (Optional\|string) Optionally create routes from private subnets to transit gateway subnets. Specify the CIDR range or a prefix-list-id that you want routed to the transit gateway.<br><br>**public subnet type options:**<br>- All shared keys above<br>- `nat_gateway_configuration` = (Optional\|string) Determines if NAT Gateways should be created and in how many AZs. Valid values = `"none"`, `"single_az"`, `"all_azs"`. Default = "none". Must also set `var.subnets.private.connect_to_public_natgw = true`.<br>- `route_to_transit_gateway` = (Optional\|string) Optionally create routes from public subnets to transit gateway subnets. Specify the CIDR range or a prefix-list-id that you want routed to the transit gateway.<br><br>**transit\_gateway subnet type options:**<br>- All shared keys above<br>- `connect_to_public_natgw` = (Optional\|string) Determines if routes to NAT Gateways should be created. Specify the CIDR range or a prefix-list-id that you want routed to nat gateway. Usually `0.0.0.0/0`. Must also set `var.subnets.public.nat_gateway_configuration`.<br>- `transit_gateway_id` = (Required\|string) Transit gateway to attach VPC to.<br>- `transit_gateway_default_route_table_association` = (Optional\|bool) Boolean whether the VPC Attachment should be associated with the EC2 Transit Gateway association default route table. This cannot be configured or perform drift detection with Resource Access Manager shared EC2 Transit Gateways.<br>- `transit_gateway_default_route_table_propagation` = (Optional\|bool) Boolean whether the VPC Attachment should propagate routes with the EC2 Transit Gateway propagation default route table. This cannot be configured or perform drift detection with Resource Access Manager shared EC2 Transit Gateways.<br>- `transit_gateway_appliance_mode_support` = (Optional\|string) Whether Appliance Mode is enabled. If enabled, a traffic flow between a source and a destination uses the same Availability Zone for the VPC attachment for the lifetime of that flow. Valid values: `disable` (default) and `enable`.<br>- `transit_gateway_dns_support` = (Optional\|string) DNS Support is used if you need the VPC to resolve public IPv4 DNS host names to private IPv4 addresses when queried from instances in another VPC attached to the transit gateway. Valid values: `enable` (default) and `disable`.<br><br>Example:<pre>subnets = {<br> public = {<br> netmask = 24<br> nat_gateway_configuration = "single_az"<br> route_to_transit_gateway = "10.1.0.0/16"<br> }<br><br> private = {<br> netmask = 24<br> connect_to_public_natgw = true<br> route_to_transit_gateway = "10.1.0.0/16"<br> }<br><br> transit_gateway = {<br> netmask = 24<br> transit_gateway_id = aws_ec2_transit_gateway.example.id<br> connect_to_public_natgw = true<br> transit_gateway_default_route_table_association = true<br> transit_gateway_default_route_table_propagation = true<br> }<br>}</pre> | `any` | n/a | yes |
240240
| <a name="input_cidr_block"></a> [cidr\_block](#input\_cidr\_block) | CIDR range to assign to VPC if creating VPC or to associte as a secondary CIDR. Overridden by var.vpc\_id output from data.aws\_vpc. | `string` | `null` | no |
241241
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to apply to all resources. | `map(string)` | `{}` | no |
242242
| <a name="input_vpc_enable_dns_hostnames"></a> [vpc\_enable\_dns\_hostnames](#input\_vpc\_enable\_dns\_hostnames) | Indicates whether the instances launched in the VPC get DNS hostnames. If enabled, instances in the VPC get DNS hostnames; otherwise, they do not. Disabled by default for nondefault VPCs. | `bool` | `true` | no |

UPGRADE-GUIDE-2.0.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
- Ability to create arbitrary amounts of subnets types. Previously was only capable of 3 types: public, private, transit gateway. The terms `public` and `transit_gateway` are reserved keywords for those subnet types and all other keys used in var.subnets.<> are assumed to be type **private**.
44
- Many private subnet related resources had to be renamed. Most changes are accomplished programatically using a [moved blocks](https://www.terraform.io/language/modules/develop/refactoring) but some require manual `terraform state mv` commands. see below.
5-
- Can pass cidr or prefix list id to any `route_to_nat` argument. Previously was a boolean that assumed `"0.0.0.0/0"` as the destination cidr.
5+
- `route_to_nat` has been changed to `connect_to_public_natgw` to clarify the nat is in the public subnet & to diverge from the `route_to` nomenclature which expects a route destination like input.
66
- Can pass cidr or prefix list id to `route_to_transit_gateway` argument. Previously was a list of CIDRs that could only accept 1 item.
77
- Many changes to Outputs available. Removed outputs marked as deprecated, separated grouped subnet attribute outputs into 3 `public_`, `tgw_`, and `private_`. Since you can have several private subnet declarations we group based on the name scheme `<your_key_name>/az`.
88

@@ -25,7 +25,7 @@ After : `route_to_transit_gateway = "10.0.0.0/8"`
2525

2626
Before: `route_to_nat = true`
2727

28-
After : `route_to_nat = "0.0.0.0/0"`
28+
After : `connect_to_public_natgw = true`
2929

3030
## Statefile Changes
3131

@@ -68,7 +68,7 @@ Remediation: See the move commands above.
6868

6969
### Invalid `for_each` argument
7070

71-
This problem is nuanced. It likely indicates that youre trying to use a prefix list as a `route_to_nat` or `route_to_transit_gateway` value in a subnet argument or transit gateway id. If you're attempting to create a resource and use it as a value in any of subnet definition, you must first [target create](https://learn.hashicorp.com/tutorials/terraform/resource-targeting) those resources. This includes both `aws_ec2_managed_prefix_list` and `aws_ec2_transit_gateway`.
71+
This problem is nuanced. It likely indicates that youre trying to use a computed value, like a resource id, as an input in the var.subnets map. Common examples would be passing transit_gateway id or prefix_list_id that is created in parallel. You must first [target create](https://learn.hashicorp.com/tutorials/terraform/resource-targeting) those resources. This includes both `aws_ec2_managed_prefix_list` and `aws_ec2_transit_gateway`.
7272

7373
Alternative to target creates, see the [transit_gateway test](https://github.com/aws-ia/terraform-aws-vpc/blob/main/test/examples_transit_gateway__test.go) for an example, we create both in a separate root and pass as variables
7474

contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ route_table_attributes_by_type_by_az = {
6767
```terraform
6868
**private subnet type options:**
6969
- All shared keys above
70-
- `route_to_nat` = (Optional|bool) <>
70+
- `connect_to_public_natgw` = (Optional|bool) <>
7171
- `route_to_transit_gateway` = (Optional|list(string)) <>
7272
```
7373

data.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ locals {
1313

1414
# constructed list of <private_subnet_key>/az
1515
private_per_az = flatten([for az in local.azs : [for subnet in local.private_subnet_names : "${subnet}/${az}"]])
16-
# list of private subnet keys with route_to_nat = true
17-
private_subnets_nat_routed = [for type in local.private_subnet_names : type if can(var.subnets[type].route_to_nat)]
18-
# private subnets with cidrs per az if route_to_nat = true ... "privatetwo/us-east-1a"
16+
# list of private subnet keys with connect_to_public_natgw = true
17+
private_subnets_nat_routed = [for type in local.private_subnet_names : type if can(var.subnets[type].connect_to_public_natgw)]
18+
# private subnets with cidrs per az if connect_to_public_natgw = true ... "privatetwo/us-east-1a"
1919
private_subnet_names_nat_routed = [for subnet in local.private_per_az : subnet if contains(local.private_subnets_nat_routed, split("/", subnet)[0])]
2020

2121
private_subnets_tgw_routed = [for type in local.private_subnet_names : type if can(var.subnets[type].route_to_transit_gateway)]

examples/ipam/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ module "vpc" {
1414
nat_gateway_configuration = "all_azs"
1515
}
1616
private = {
17-
netmask = 24
18-
route_to_nat = "0.0.0.0/0"
17+
netmask = 24
18+
connect_to_public_natgw = true
1919
}
2020
}
2121
}

examples/public_private_flow_logs/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ module "vpc" {
1616
private = {
1717
# omitting name_prefix defaults value to "private"
1818
# name_prefix = "private"
19-
netmask = 24
20-
route_to_nat = "0.0.0.0/0"
19+
netmask = 24
20+
connect_to_public_natgw = true
2121
}
2222
}
2323

examples/transit_gateway/main.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module "vpc" {
2-
source = "aws-ia/vpc/aws"
3-
version = ">= 2.0.0"
2+
# source = "aws-ia/vpc/aws"
3+
# version = ">= 2.0.0"
4+
source = "../.."
45

56
name = "tgw"
67
cidr_block = "10.0.0.0/16"
@@ -15,7 +16,7 @@ module "vpc" {
1516

1617
private_with_egress = {
1718
netmask = 24
18-
route_to_nat = "0.0.0.0/0"
19+
connect_to_public_natgw = true
1920
route_to_transit_gateway = var.prefix_list_id
2021
}
2122

@@ -26,7 +27,7 @@ module "vpc" {
2627
transit_gateway = {
2728
netmask = 28
2829
transit_gateway_id = var.tgw_id
29-
route_to_nat = "0.0.0.0/0"
30+
connect_to_public_natgw = true
3031
transit_gateway_default_route_table_association = true
3132
transit_gateway_default_route_table_propagation = true
3233
transit_gateway_appliance_mode_support = "enable"

main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ resource "aws_route" "private_to_nat" {
158158
for_each = toset(try(local.private_subnet_names_nat_routed, []))
159159

160160
route_table_id = awscc_ec2_route_table.private[each.key].id
161-
destination_cidr_block = var.subnets[split("/", each.key)[0]].route_to_nat
161+
destination_cidr_block = "0.0.0.0/0"
162162
# try to get nat for AZ, else use singular nat
163163
nat_gateway_id = try(aws_nat_gateway.main[split("/", each.key)[1]].id, aws_nat_gateway.main[local.nat_configuration[0]].id)
164164
}
@@ -208,11 +208,11 @@ resource "awscc_ec2_subnet_route_table_association" "tgw" {
208208
}
209209

210210
resource "aws_route" "tgw_to_nat" {
211-
for_each = (can(var.subnets.transit_gateway.route_to_nat) && contains(local.subnet_keys, "public")) ? toset(local.azs) : toset([])
211+
for_each = (can(var.subnets.transit_gateway.connect_to_public_natgw) && contains(local.subnet_keys, "public")) ? toset(local.azs) : toset([])
212212

213213

214214
route_table_id = awscc_ec2_route_table.tgw[each.key].id
215-
destination_cidr_block = var.subnets.transit_gateway.route_to_nat
215+
destination_cidr_block = "0.0.0.0/0"
216216
# try to get nat for AZ, else use singular nat
217217
nat_gateway_id = try(aws_nat_gateway.main[each.key].id, aws_nat_gateway.main[local.nat_configuration[0]].id)
218218
}

0 commit comments

Comments
 (0)