Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
tkerdoncuff committed Jan 24, 2024
1 parent eb23059 commit 67d817a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
locals {
public_subnets = { for k, v in aws_subnet.quortex : k => v if v.map_public_ip_on_launch == true }
private_subnets = { for k, v in aws_subnet.quortex : k => v if v.map_public_ip_on_launch == false }
public_subnets = { for k, v in aws_subnet.quortex : k => v if v.map_public_ip_on_launch == true }
private_subnets = { for k, v in aws_subnet.quortex : k => v if v.map_public_ip_on_launch == false }
}
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ resource "aws_route_table" "quortex_private" {

# Route to the NAT, if NAT is enabled...
dynamic "route" {
for_each = length([for k, v in aws_nat_gateway.quortex : v if v.subnet_key == each.key])[0] > 0 ? [1] : []
for_each = length([for k, v in aws_nat_gateway.quortex : v if v.subnet_key == each.key]) > 0 ? [1] : []

content {
cidr_block = "0.0.0.0/0"
Expand All @@ -130,7 +130,7 @@ resource "aws_route_table" "quortex_private" {

# ...otherwise, route to the Internet Gateway
dynamic "route" {
for_each = length([for k, v in aws_nat_gateway.quortex : v if v.subnet_key == each.key])[0] == 0 ? [1] : []
for_each = length([for k, v in aws_nat_gateway.quortex : v if v.subnet_key == each.key]) == 0 ? [1] : []

content {
cidr_block = "0.0.0.0/0"
Expand Down
8 changes: 4 additions & 4 deletions nat_gateway.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
# A static Elastic IP used for Quortex cluster External NAT Gateway IP.
# This resource is created for each nat gateway where no existing EIP is specified.
resource "aws_eip" "quortex" {
for_each = {for k,v in var.nat_gateways : k => v if v.eip_allocation_id == null}
for_each = { for k, v in var.nat_gateways : k => v if v.eip_allocation_id == null }

tags = merge({ "Name" = each.key }, var.tags)
}

# An existing Elastic IP that will be attached to NAT gateways when
# the id is defined. This datasource is used only to display the IP address
data "aws_eip" "existing_eip" {
for_each = {for k,v in var.nat_gateways : k => v if v.eip_allocation_id != null}
for_each = { for k, v in var.nat_gateways : k => v if v.eip_allocation_id != null }

id = each.value.eip_allocation_id
}

# Nat gateways depending on the list passed in the nat_gateways variable
resource "aws_nat_gateway" "quortex" {
for_each = {for k,v in var.nat_gateways : k => v if local.public_subnets[v.subnet_key] != null}
for_each = { for k, v in var.nat_gateways : k => v if local.public_subnets[v.subnet_key] != null }

allocation_id = each.value.eip_allocation_id == null ? aws_eip.quortex[each.key].id : data.aws_eip.existing_eip[each.key].id
subnet_id = local.public_subnets[each.value.subnet_key].id
Expand All @@ -44,4 +44,4 @@ resource "aws_nat_gateway" "quortex" {
}, var.tags)

depends_on = [aws_internet_gateway.quortex]
}
}
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ output "route_table_ids_private" {
}

output "nat_eip_id" {
value = concat(values(aws_eip.quortex[*].id), values({for k,v in var.nat_gateways : k => v if v.eip_allocation_id != null}[*].eip_allocation_id))
value = concat(values(aws_eip.quortex[*].id), values({ for k, v in var.nat_gateways : k => v if v.eip_allocation_id != null }[*].eip_allocation_id))
description = "The IDs of the Elastic IPs associated to the Quortex cluster External NAT Gateways."
}

Expand Down
4 changes: 2 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ variable "nat_gateway_name_prefix" {
}

variable "nat_gateways" {
type = map(object({subnet_key = string, eip_allocation_id = string }))
type = map(object({ subnet_key = string, eip_allocation_id = string }))
description = <<EOT
The NAT gateways configuration, a map of object, each with a subnet_key that must
match a key of the given subnets variable and an optional eip allocation id.
Expand Down Expand Up @@ -95,4 +95,4 @@ variable "tags" {
type = map(any)
description = "The tags (a map of key/value pairs) to be applied to created resources."
default = {}
}
}

0 comments on commit 67d817a

Please sign in to comment.