Skip to content

Commit 88582d3

Browse files
Merge pull request #1 from HasseJohansen/feat/disable-public-default-route
feat: Add toggle to disable public default route
2 parents 7c1f791 + 1cf996d commit 88582d3

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,18 @@ module "vpc_cidr_from_ipam" {
229229
}
230230
```
231231

232+
## Disable default route creation for public subnets
233+
234+
Disabling the creation of the default can be used if you want have a default pointing to other gateways than the internet gateway(IGW)
235+
236+
This is useful if you ex. would want to route all traffic through a AWS Network Firewall, but can also be useful for other purposes
237+
238+
You disable the creation by specifying setting the var.public_disable_default_route variable ex.
239+
240+
```hcl
241+
public_disable_default_route = true # <= By default it is false to maintain existing behavior
242+
```
243+
232244
## Examples
233245

234246
- [Complete VPC](https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/complete) with VPC Endpoints.
@@ -545,6 +557,7 @@ No modules.
545557
| <a name="input_propagate_public_route_tables_vgw"></a> [propagate\_public\_route\_tables\_vgw](#input\_propagate\_public\_route\_tables\_vgw) | Should be true if you want route table propagation | `bool` | `false` | no |
546558
| <a name="input_public_acl_tags"></a> [public\_acl\_tags](#input\_public\_acl\_tags) | Additional tags for the public subnets network ACL | `map(string)` | `{}` | no |
547559
| <a name="input_public_dedicated_network_acl"></a> [public\_dedicated\_network\_acl](#input\_public\_dedicated\_network\_acl) | Whether to use dedicated network ACL (not default) and custom rules for public subnets | `bool` | `false` | no |
560+
| <a name="input_public_disable_default_route"></a> [public\_disable\_default\_route](#input\_public\_disable\_default\_route) | Disable default route to internet gateway for public subnets | `bool` | `false` | no |
548561
| <a name="input_public_inbound_acl_rules"></a> [public\_inbound\_acl\_rules](#input\_public\_inbound\_acl\_rules) | Public subnets inbound network ACLs | `list(map(string))` | <pre>[<br/> {<br/> "cidr_block": "0.0.0.0/0",<br/> "from_port": 0,<br/> "protocol": "-1",<br/> "rule_action": "allow",<br/> "rule_number": 100,<br/> "to_port": 0<br/> }<br/>]</pre> | no |
549562
| <a name="input_public_outbound_acl_rules"></a> [public\_outbound\_acl\_rules](#input\_public\_outbound\_acl\_rules) | Public subnets outbound network ACLs | `list(map(string))` | <pre>[<br/> {<br/> "cidr_block": "0.0.0.0/0",<br/> "from_port": 0,<br/> "protocol": "-1",<br/> "rule_action": "allow",<br/> "rule_number": 100,<br/> "to_port": 0<br/> }<br/>]</pre> | no |
550563
| <a name="input_public_route_table_tags"></a> [public\_route\_table\_tags](#input\_public\_route\_table\_tags) | Additional tags for the public route tables | `map(string)` | `{}` | no |

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ resource "aws_route_table_association" "public" {
186186
}
187187

188188
resource "aws_route" "public_internet_gateway" {
189-
count = local.create_public_subnets && var.create_igw ? local.num_public_route_tables : 0
189+
count = alltrue([local.create_public_subnets, var.create_igw, var.public_disable_default_route]) ? local.num_public_route_tables : 0
190190

191191
route_table_id = aws_route_table.public[count.index].id
192192
destination_cidr_block = "0.0.0.0/0"
@@ -198,7 +198,7 @@ resource "aws_route" "public_internet_gateway" {
198198
}
199199

200200
resource "aws_route" "public_internet_gateway_ipv6" {
201-
count = local.create_public_subnets && var.create_igw && var.enable_ipv6 ? local.num_public_route_tables : 0
201+
count = alltrue([local.create_public_subnets, var.create_igw, var.enable_ipv6, var.public_disable_default_route]) ? local.num_public_route_tables : 0
202202

203203
route_table_id = aws_route_table.public[count.index].id
204204
destination_ipv6_cidr_block = "::/0"

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ variable "public_route_table_tags" {
274274
default = {}
275275
}
276276

277+
variable "public_disable_default_route" {
278+
description = "Disable default route to internet gateway for public subnets"
279+
type = bool
280+
default = false
281+
}
282+
277283
################################################################################
278284
# Public Network ACLs
279285
################################################################################

0 commit comments

Comments
 (0)