Skip to content

Commit 380910a

Browse files
committed
chore: ignore the nat gateway configuration when gateway is not enabled
1 parent 987cc08 commit 380910a

File tree

4 files changed

+82
-22
lines changed

4 files changed

+82
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ The `terraform-docs` utility is used to generate this README. Follow the below s
251251
| <a name="input_private_subnet_tags"></a> [private\_subnet\_tags](#input\_private\_subnet\_tags) | Additional tags for the private subnets | `map(string)` | `{}` | no |
252252
| <a name="input_public_subnet_netmask"></a> [public\_subnet\_netmask](#input\_public\_subnet\_netmask) | The netmask for the public subnets | `number` | `0` | no |
253253
| <a name="input_public_subnet_tags"></a> [public\_subnet\_tags](#input\_public\_subnet\_tags) | Additional tags for the public subnets | `map(string)` | `{}` | no |
254-
| <a name="input_transit_gateway_id"></a> [transit\_gateway\_id](#input\_transit\_gateway\_id) | If enabled, and not lookup is disabled, the transit gateway id to connect to | `string` | `""` | no |
254+
| <a name="input_transit_gateway_id"></a> [transit\_gateway\_id](#input\_transit\_gateway\_id) | If enabled, and not lookup is disabled, the transit gateway id to connect to | `string` | `null` | no |
255255
| <a name="input_transit_gateway_routes"></a> [transit\_gateway\_routes](#input\_transit\_gateway\_routes) | If enabled, this is the cidr block to route down the transit gateway | `map(string)` | <pre>{<br/> "private": "10.0.0.0/8"<br/>}</pre> | no |
256256
| <a name="input_transit_subnet_tags"></a> [transit\_subnet\_tags](#input\_transit\_subnet\_tags) | Additional tags for the transit subnets | `map(string)` | `{}` | no |
257257
| <a name="input_vpc_cidr"></a> [vpc\_cidr](#input\_vpc\_cidr) | An optional cidr block to assign to the VPC (if not using IPAM) | `string` | `null` | no |

locals.tf

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
locals {
22
# Th current region
33
region = data.aws_region.current.name
4+
# Indicates if the transit gateway is being proivisioned
5+
enable_transit_gateway = var.transit_gateway_id != null
46
# The id for the transit_gateway_id passed into the module
5-
transit_gateway_id = var.enable_transit_gateway ? var.transit_gateway_id : null
6-
# Is the routes to propagate down the transit gateway
7-
transit_routes = var.enable_transit_gateway && length(var.transit_gateway_routes) > 0 ? var.transit_gateway_routes : {}
7+
transit_gateway_id = local.enable_transit_gateway ? var.transit_gateway_id : null
8+
# Is the routes to propagate down the transit gateway
9+
transit_routes = local.enable_transit_gateway && length(var.transit_gateway_routes) > 0 ? var.transit_gateway_routes : {}
10+
# NAT Configuration mode
11+
nat_gateway_mode = var.enable_nat_gateway ? var.nat_gateway_mode : "none"
812
# The configuration for the private subnets
913
private_subnet = var.private_subnet_netmask > 0 ? {
1014
private = {
11-
connect_to_public_natgw = var.enable_nat_gateway ? true : false
15+
connect_to_public_natgw = var.enable_nat_gateway
1216
netmask = var.private_subnet_netmask
1317
tags = merge(var.tags, var.private_subnet_tags)
1418
}
1519
} : null
1620
# Public subnets are optional
1721
public_subnet = var.public_subnet_netmask > 0 ? {
1822
public = {
19-
nat_gateway_configuration = var.nat_gateway_mode
23+
nat_gateway_configuration = local.nat_gateway_mode
2024
netmask = var.public_subnet_netmask
2125
tags = merge(var.tags, var.public_subnet_tags)
2226
}
2327
} : null
24-
# Configuration for the transit subnets
25-
transit_subnet = var.enable_transit_gateway ? {
28+
# Configuration for the transit subnets
29+
transit_subnet = local.enable_transit_gateway ? {
2630
transit_gateway = {
2731
connect_to_public_natgw = var.enable_transit_gateway_subnet_natgw
2832
netmask = 28
@@ -39,28 +43,28 @@ locals {
3943
private_subnet_cidrs = [for k, x in module.vpc.private_subnet_attributes_by_az : x.cidr_block if startswith(k, "private/")]
4044
# A map of private subnet id to cidr block
4145
private_subnet_cidr_by_id = { for k, x in module.vpc.private_subnet_attributes_by_az : x.id => x.cidr_block if startswith(k, "private/") }
42-
# A map of az to private subnet id
46+
# A map of az to private subnet id
4347
private_subnet_id_by_az = { for k, x in module.vpc.private_subnet_attributes_by_az : trimprefix(k, "private/") => x.id if startswith(k, "private/") }
44-
# A map of az to public subnet id
48+
# A map of az to public subnet id
4549
public_subnet_id_by_az = var.public_subnet_netmask > 0 ? { for k, x in module.vpc.public_subnet_attributes_by_az : k => x.id } : {}
46-
# A map of public subnet id to cidr block
50+
# A map of public subnet id to cidr block
4751
public_subnet_cidr_by_id = var.public_subnet_netmask > 0 ? { for k, x in module.vpc.public_subnet_attributes_by_az : x.id => x.cidr_block } : {}
48-
# public_subnet ranges
52+
# public_subnet ranges
4953
public_subnet_cidrs = var.public_subnet_netmask > 0 ? [for k, x in module.vpc.public_subnet_attributes_by_az : x.cidr_block] : []
5054
# The subnet id for the private subnets
5155
private_subnet_ids = [for k, x in module.vpc.private_subnet_attributes_by_az : x.id if startswith(k, "private/")]
5256
# The subnet id for the public subnets
5357
public_subnet_ids = var.public_subnet_netmask > 0 ? [for k, x in module.vpc.public_subnet_attributes_by_az : x.id] : []
5458
# The subnet id for the transit subnets
55-
transit_subnet_ids = var.enable_transit_gateway ? [for k, x in module.vpc.tgw_subnet_attributes_by_az : x.id] : []
56-
# A list of transit route table ids
57-
transit_route_table_ids = var.enable_transit_gateway ? [for k, x in module.vpc.rt_attributes_by_type_by_az.transit_gateway : x.id] : []
59+
transit_subnet_ids = local.enable_transit_gateway ? [for k, x in module.vpc.tgw_subnet_attributes_by_az : x.id] : []
60+
# A list of transit route table ids
61+
transit_route_table_ids = local.enable_transit_gateway ? [for k, x in module.vpc.rt_attributes_by_type_by_az.transit_gateway : x.id] : []
5862
# The routing tables for the private subnets
5963
private_route_table_ids = [for k, x in module.vpc.rt_attributes_by_type_by_az.private : x.id]
60-
# The transgit gateway route table ids
64+
# The transgit gateway route table ids
6165
public_route_table_ids = var.public_subnet_netmask > 0 ? [for k, x in module.vpc.rt_attributes_by_type_by_az.public : x.id] : []
62-
# A map of the route table ids for the transit gateway by az
63-
transit_route_table_by_az = var.enable_transit_gateway ? { for k, v in module.vpc.rt_attributes_by_type_by_az.transit_gateway : k => v.id } : {}
66+
# A map of the route table ids for the transit gateway by az
67+
transit_route_table_by_az = local.enable_transit_gateway ? { for k, v in module.vpc.rt_attributes_by_type_by_az.transit_gateway : k => v.id } : {}
6468

6569
subnets = merge(
6670
local.private_subnet,
@@ -71,8 +75,9 @@ locals {
7175

7276
# A list of the private endpoints to enable ssm
7377
ssm_endpoints = var.enable_ssm ? ["ssmmessages", "ssm", "ec2messages"] : []
74-
# enabled_endpotints is a list of all the private endpoints to enable
78+
# enabled_endpotints is a list of all the private endpoints to enable
7579
enabled_endpoints = concat(var.enable_private_endpoints, local.ssm_endpoints)
76-
## Build the list of resolver rules to associate with the vpc
80+
## Build the list of resolver rules to associate with the vpc
7781
resolver_rules = var.enable_route53_resolver_rules ? [for id in data.aws_route53_resolver_rules.current.resolver_rule_ids : id if !contains(var.exclude_route53_resolver_rules, id)] : []
78-
}
82+
}
83+

modules/shared/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!-- BEGIN_TF_DOCS -->
2+
## Providers
3+
4+
| Name | Version |
5+
|------|---------|
6+
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 5.0 |
7+
8+
## Inputs
9+
10+
| Name | Description | Type | Default | Required |
11+
|------|-------------|------|---------|:--------:|
12+
| <a name="input_name"></a> [name](#input\_name) | Is the name of the network to provision | `string` | n/a | yes |
13+
| <a name="input_subnets"></a> [subnets](#input\_subnets) | A collection of subnets to provison, and rules to distribute to accounts | <pre>map(object({<br/> availability_zones = optional(number, null)<br/> # The availability zones to deploy the subnet into, else default to vpc availability zones<br/> netmask = optional(number, null)<br/> # The netmask for the subnet each of the subnets against the availability zones<br/> tags = optional(map(string), null)<br/> # Additional tags for the subnets<br/> shared = optional(object({<br/> accounts = optional(list(string), null)<br/> # A list of accounts to share the subnets with<br/> organization_units = optional(list(string), null)<br/> # A list of organization units to share the subnets with<br/> }), null)<br/> }))</pre> | n/a | yes |
14+
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to apply to all resources | `map(string)` | n/a | yes |
15+
| <a name="input_associated_resolver_rules"></a> [associated\_resolver\_rules](#input\_associated\_resolver\_rules) | A list of resolver rules to associate with the VPC | `list(string)` | `[]` | no |
16+
| <a name="input_associated_route53_zones"></a> [associated\_route53\_zones](#input\_associated\_route53\_zones) | A list of route53 zones to associate with the VPC | `list(string)` | `[]` | no |
17+
| <a name="input_availability_zones"></a> [availability\_zones](#input\_availability\_zones) | The number of availability zone the network should be deployed into | `number` | `2` | no |
18+
| <a name="input_enable_default_route_table_association"></a> [enable\_default\_route\_table\_association](#input\_enable\_default\_route\_table\_association) | Indicates the transit gateway default route table should be associated with the subnets | `bool` | `true` | no |
19+
| <a name="input_enable_default_route_table_propagation"></a> [enable\_default\_route\_table\_propagation](#input\_enable\_default\_route\_table\_propagation) | Indicates the transit gateway default route table should be propagated to the subnets | `bool` | `true` | no |
20+
| <a name="input_enable_nat_gateway"></a> [enable\_nat\_gateway](#input\_enable\_nat\_gateway) | Indicates the network should provison nat gateways | `bool` | `false` | no |
21+
| <a name="input_enable_private_endpoints"></a> [enable\_private\_endpoints](#input\_enable\_private\_endpoints) | Indicates the network should provision private endpoints | `list(string)` | `[]` | no |
22+
| <a name="input_enable_ssm"></a> [enable\_ssm](#input\_enable\_ssm) | Indicates we should provision SSM private endpoints | `bool` | `false` | no |
23+
| <a name="input_enable_transit_gateway"></a> [enable\_transit\_gateway](#input\_enable\_transit\_gateway) | Indicates the network should provison nat gateways | `bool` | `false` | no |
24+
| <a name="input_enable_transit_gateway_appliance_mode"></a> [enable\_transit\_gateway\_appliance\_mode](#input\_enable\_transit\_gateway\_appliance\_mode) | Indicates the network should be connected to a transit gateway in appliance mode | `bool` | `false` | no |
25+
| <a name="input_enable_transit_gateway_subnet_natgw"></a> [enable\_transit\_gateway\_subnet\_natgw](#input\_enable\_transit\_gateway\_subnet\_natgw) | Indicates if the transit gateway subnets should be connected to a nat gateway | `bool` | `false` | no |
26+
| <a name="input_ipam_pool_id"></a> [ipam\_pool\_id](#input\_ipam\_pool\_id) | An optional pool id to use for IPAM pool to use | `string` | `null` | no |
27+
| <a name="input_transit_gateway_id"></a> [transit\_gateway\_id](#input\_transit\_gateway\_id) | If enabled, and not lookup is disabled, the transit gateway id to connect to | `string` | `""` | no |
28+
| <a name="input_transit_gateway_routes"></a> [transit\_gateway\_routes](#input\_transit\_gateway\_routes) | If enabled, this is the cidr block to route down the transit gateway | `map(string)` | <pre>{<br/> "private": "10.0.0.0/8"<br/>}</pre> | no |
29+
| <a name="input_transit_subnet_tags"></a> [transit\_subnet\_tags](#input\_transit\_subnet\_tags) | Additional tags for the transit subnets | `map(string)` | `{}` | no |
30+
| <a name="input_vpc_cidr"></a> [vpc\_cidr](#input\_vpc\_cidr) | An optional cidr block to assign to the VPC (if not using IPAM) | `string` | `null` | no |
31+
| <a name="input_vpc_instance_tenancy"></a> [vpc\_instance\_tenancy](#input\_vpc\_instance\_tenancy) | The name of the VPC to create | `string` | `"default"` | no |
32+
| <a name="input_vpc_netmask"></a> [vpc\_netmask](#input\_vpc\_netmask) | An optional range assigned to the VPC | `number` | `null` | no |
33+
34+
## Outputs
35+
36+
| Name | Description |
37+
|------|-------------|
38+
| <a name="output_nat_public_ips"></a> [nat\_public\_ips](#output\_nat\_public\_ips) | The public IPs of the NAT Gateways i.e [public\_ip, public\_ip] |
39+
| <a name="output_natgw_id_per_az"></a> [natgw\_id\_per\_az](#output\_natgw\_id\_per\_az) | The IDs of the NAT Gateways (see aws-ia/vpc/aws for details) |
40+
| <a name="output_private_route_table_ids"></a> [private\_route\_table\_ids](#output\_private\_route\_table\_ids) | The IDs of the private route tables ie. [route\_table\_id, route\_table\_id] |
41+
| <a name="output_private_subnet_attributes_by_az"></a> [private\_subnet\_attributes\_by\_az](#output\_private\_subnet\_attributes\_by\_az) | The attributes of the private subnets (see aws-ia/vpc/aws for details) |
42+
| <a name="output_private_subnet_cidr_by_id"></a> [private\_subnet\_cidr\_by\_id](#output\_private\_subnet\_cidr\_by\_id) | A map of subnet id to CIDR block of the private subnets i.e. subnet\_id => cidr\_block |
43+
| <a name="output_private_subnet_cidrs"></a> [private\_subnet\_cidrs](#output\_private\_subnet\_cidrs) | A list of the CIDRs for the private subnets |
44+
| <a name="output_private_subnet_id_by_az"></a> [private\_subnet\_id\_by\_az](#output\_private\_subnet\_id\_by\_az) | A map of availability zone to subnet id of the private subnets i.e. eu-west-2a => subnet\_id |
45+
| <a name="output_private_subnet_ids"></a> [private\_subnet\_ids](#output\_private\_subnet\_ids) | The IDs of the private subnets i.e. [subnet\_id, subnet\_id] |
46+
| <a name="output_rt_attributes_by_type_by_az"></a> [rt\_attributes\_by\_type\_by\_az](#output\_rt\_attributes\_by\_type\_by\_az) | The attributes of the route tables (see aws-ia/vpc/aws for details) |
47+
| <a name="output_transit_gateway_attachment_id"></a> [transit\_gateway\_attachment\_id](#output\_transit\_gateway\_attachment\_id) | The ID of the transit gateway attachment if enabled |
48+
| <a name="output_transit_route_table_by_az"></a> [transit\_route\_table\_by\_az](#output\_transit\_route\_table\_by\_az) | A map of availability zone to transit gateway route table ID i.e eu-west-2a => route\_table\_id |
49+
| <a name="output_transit_route_table_ids"></a> [transit\_route\_table\_ids](#output\_transit\_route\_table\_ids) | The IDs of the transit gateway route tables ie. [route\_table\_id, route\_table\_id] |
50+
| <a name="output_transit_subnet_attributes_by_az"></a> [transit\_subnet\_attributes\_by\_az](#output\_transit\_subnet\_attributes\_by\_az) | The attributes of the transit gateway subnets (see aws-ia/vpc/aws for details) |
51+
| <a name="output_transit_subnet_ids"></a> [transit\_subnet\_ids](#output\_transit\_subnet\_ids) | The IDs of the transit gateway subnets ie. [subnet\_id, subnet\_id] |
52+
| <a name="output_vpc_attributes"></a> [vpc\_attributes](#output\_vpc\_attributes) | The attributes of the VPC (see aws-ia/vpc/aws for details) |
53+
| <a name="output_vpc_cidr"></a> [vpc\_cidr](#output\_vpc\_cidr) | The CIDR block of the VPC |
54+
| <a name="output_vpc_id"></a> [vpc\_id](#output\_vpc\_id) | The ID of the VPC |
55+
<!-- END_TF_DOCS -->

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ variable "tags" {
118118
variable "transit_gateway_id" {
119119
description = "If enabled, and not lookup is disabled, the transit gateway id to connect to"
120120
type = string
121-
default = ""
121+
default = null
122122
}
123123

124124
variable "transit_gateway_routes" {

0 commit comments

Comments
 (0)