Skip to content

Commit 5e00a02

Browse files
improvement: allow specific tags on public and private subnets by name
1 parent caffe19 commit 5e00a02

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

main.tf

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ resource "aws_subnet" "public" {
120120
},
121121
var.tags,
122122
var.public_subnet_tags,
123-
lookup(var.public_subnet_tags_per_az, element(var.azs, count.index), {})
123+
lookup(var.public_subnet_tags_per_az, element(var.azs, count.index), {}),
124+
lookup(var.public_subnet_tags_per_name, try(
125+
var.public_subnet_names[count.index],
126+
format("${var.name}-${var.public_subnet_suffix}-%s", element(var.azs, count.index))
127+
))
124128
)
125129
}
126130

@@ -255,7 +259,11 @@ resource "aws_subnet" "private" {
255259
},
256260
var.tags,
257261
var.private_subnet_tags,
258-
lookup(var.private_subnet_tags_per_az, element(var.azs, count.index), {})
262+
lookup(var.private_subnet_tags_per_az, element(var.azs, count.index), {}),
263+
lookup(var.private_subnet_tags_per_name, try(
264+
var.private_subnet_names[count.index],
265+
format("${var.name}-${var.private_subnet_suffix}-%s", element(var.azs, count.index))
266+
))
259267
)
260268
}
261269

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ variable "public_subnet_tags_per_az" {
256256
default = {}
257257
}
258258

259+
variable "public_subnet_tags_per_name" {
260+
description = "Additional tags for the public subnets where the primary key is the Name"
261+
type = map(map(string))
262+
default = {}
263+
}
264+
259265
variable "public_route_table_tags" {
260266
description = "Additional tags for the public route tables"
261267
type = map(string)
@@ -390,6 +396,12 @@ variable "private_subnet_tags_per_az" {
390396
default = {}
391397
}
392398

399+
variable "private_subnet_tags_per_name" {
400+
description = "Additional tags for the private subnets where the primary key is the Name"
401+
type = map(map(string))
402+
default = {}
403+
}
404+
393405
variable "private_route_table_tags" {
394406
description = "Additional tags for the private route tables"
395407
type = map(string)

0 commit comments

Comments
 (0)