Skip to content

Commit

Permalink
Handle multiple route tables
Browse files Browse the repository at this point in the history
  • Loading branch information
RaJiska committed Dec 1, 2023
1 parent d013102 commit 37bb04d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
10 changes: 8 additions & 2 deletions docs/header.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ an ASG
- Cloudwatch metrics reported similar to those available with the managed NAT Gateway
- Use of spot instances instead of on-demand for reduced costs

/!\ Some of of those features, even though merged upstream, may require you to build the AMI until they are officially published.

## Example

```hcl
Expand All @@ -19,10 +21,14 @@ module "fck-nat" {
name = "my-fck-nat"
vpc_id = "vpc-abc1234"
subnet_id = "subnet-abc1234"
update_route_table = true
route_table_id = "rtb-abc1234"
# ha_mode = true # Enables high-availability mode
# eip_allocation_ids = ["eipalloc-abc1234"] # Allocation ID of an existing EIP
# use_cloudwatch_agent = true # Enables Cloudwatch agent and have metrics reported
update_route_tables = true
route_tables_ids = {
"your-rtb-name-A' = "rtb-abc1234Foo"
"your-rtb-name-B' = "rtb-abc1234Bar"
}
}
```
15 changes: 9 additions & 6 deletions examples/full/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ data "aws_region" "current" {}
module "fck-nat" {
source = "../../"

name = local.name
vpc_id = aws_vpc.main.id
subnet_id = aws_subnet.public.id
update_route_table = true
route_table_id = aws_route_table.private.id
ha_mode = false
name = local.name
vpc_id = aws_vpc.main.id
subnet_id = aws_subnet.public.id
ha_mode = true

update_route_tables = true
route_tables_ids = {
"private" = aws_route_table.private.id
}
}
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ resource "aws_network_interface" "main" {
}

resource "aws_route" "main" {
count = var.update_route_table ? 1 : 0
for_each = var.update_route_tables || var.update_route_tables ? merge(var.route_tables_ids, var.route_table_id != null ? { RESERVED_FKC_NAT = var.route_table_id } : {}) : {}

route_table_id = var.route_table_id
route_table_id = each.value
destination_cidr_block = "0.0.0.0/0"
network_interface_id = aws_network_interface.main.id
}
Expand Down
16 changes: 14 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,29 @@ variable "subnet_id" {
}

variable "update_route_table" {
description = "Whether or not to update the route table with the NAT instance"
description = "Deprecated. Use update_route_tables instead"
type = bool
default = false
}

variable "update_route_tables" {
description = "Whether or not to update the route tables with the NAT instance"
type = bool
default = false
}

variable "route_table_id" {
description = "Route table to update. Only valid if update_route_table is true"
description = "Deprecated. Use route_tables_ids instead"
type = string
default = null
}

variable "route_tables_ids" {
description = "Route tables to update. Only valid if update_route_tables is true"
type = map(string)
default = {}
}

variable "encryption" {
description = "Whether or not to encrypt the EBS volume"
type = bool
Expand Down

0 comments on commit 37bb04d

Please sign in to comment.