Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 33 additions & 20 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,23 @@ resource "aws_subnet" "public" {
private_dns_hostname_type_on_launch = var.public_subnet_private_dns_hostname_type_on_launch
vpc_id = local.vpc_id

tags = merge(
{
Name = try(
var.public_subnet_names[count.index],
format("${var.name}-${var.public_subnet_suffix}-%s", element(var.azs, count.index))
dynamic "tags" {
for_each = var.enable_public_subnet_tags ? [1] : []
content {
tags = merge(
{
Name = try(
var.public_subnet_names[count.index],
format("${var.name}-${var.public_subnet_suffix}-%s", element(var.azs, count.index))
)
},
var.tags,
var.public_subnet_tags,
lookup(var.public_subnet_tags_per_az, element(var.azs, count.index), {})
)
},
var.tags,
var.public_subnet_tags,
lookup(var.public_subnet_tags_per_az, element(var.azs, count.index), {})
)
}
}

}

locals {
Expand Down Expand Up @@ -246,17 +252,24 @@ resource "aws_subnet" "private" {
private_dns_hostname_type_on_launch = var.private_subnet_private_dns_hostname_type_on_launch
vpc_id = local.vpc_id

tags = merge(
{
Name = try(
var.private_subnet_names[count.index],
format("${var.name}-${var.private_subnet_suffix}-%s", element(var.azs, count.index))
dynamic "tags" {
for_each = var.enable_private_subnet_tags ? [1] : []
content {
tags = merge(
{
Name = try(
var.private_subnet_names[count.index],
format("${var.name}-${var.private_subnet_suffix}-%s", element(var.azs, count.index))
)
},
var.tags,
var.private_subnet_tags,
lookup(var.private_subnet_tags_per_az, element(var.azs, count.index), {})
)
},
var.tags,
var.private_subnet_tags,
lookup(var.private_subnet_tags_per_az, element(var.azs, count.index), {})
)
}
}


}

# There are as many routing tables as the number of NAT gateways
Expand Down
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ variable "public_subnets" {
default = []
}

variable "enable_public_subnet_tags" {
description = "Indicates whether tags should be applied to public subnets. Default: `true`"
type = bool
default = true
}

variable "public_subnet_assign_ipv6_address_on_creation" {
description = "Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is `false`"
type = bool
Expand Down Expand Up @@ -318,6 +324,12 @@ variable "private_subnets" {
default = []
}

variable "enable_private_subnet_tags" {
description = "Indicates whether tags should be applied to private subnets. Default: `true`"
type = bool
default = true
}

variable "private_subnet_assign_ipv6_address_on_creation" {
description = "Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is `false`"
type = bool
Expand Down
Loading