Skip to content

Commit 664c642

Browse files
committed
🔧 add extra tags config
1 parent 86a059c commit 664c642

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ module "test" {
3030
| name_prefix | a name prefix used to tag vpc | `string` | true | yes |
3131
| vpc_cidr | vpc cidr block | `string` | false | yes |
3232
| public_subnets | public subnets map, availability zone map to cidr block | `map` | false | yes |
33+
| extra_public_subnet_tags | extra tags to add to public subnet | `map` | false | false |
3334
| private_subnets | private subnets map, availability zone map to cidr block | `map` | false | yes |
35+
| extra_private_subnet_tags | extra tags to add to private subnet | `map` | false | false |
3436
| natgateway | nat gateway list of availability zone to spread | `list` | false | yes |
3537

3638
## output

example/main.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ module "test" {
88
b = "10.17.2.0/23"
99
c = "10.17.4.0/23"
1010
}
11+
extra_public_subnet_tags = {
12+
"kubernetes.io/cluster/my-cluster" = "shared"
13+
}
14+
extra_private_subnet_tags = {
15+
"kubernetes.io/cluster/my-cluster" = "shared"
16+
}
1117
private_subnets = {
1218
a = "10.17.6.0/23"
1319
b = "10.17.8.0/23"
@@ -16,7 +22,7 @@ module "test" {
1622
}
1723

1824
output "public-subnet-ids" {
19-
value = [ for k,v in module.test.public-subnet-ids: v]
25+
value = [for k, v in module.test.public-subnet-ids : v]
2026
}
2127
output "a-private-subnet-id" {
2228
value = module.test.private-subnet-ids["a"]

main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ resource "aws_subnet" "public-subnet" {
5353
cidr_block = each.value
5454
availability_zone = format("%s%s", data.aws_region.current.name, each.key)
5555
map_public_ip_on_launch = "true"
56-
tags = {
56+
tags = merge({
5757
"Name" = format("%s-public-%s", var.name_prefix, each.key)
58-
}
58+
}, var.extra_public_subnet_tags)
5959
}
6060
resource "aws_route_table_association" "public-rba" {
6161
for_each = var.public_subnets
@@ -84,9 +84,9 @@ resource "aws_subnet" "private-subnet" {
8484
cidr_block = each.value
8585
availability_zone = format("%s%s", data.aws_region.current.name, each.key)
8686
map_public_ip_on_launch = "false"
87-
tags = {
87+
tags = merge({
8888
"Name" = format("%s-private-%s", var.name_prefix, each.key)
89-
}
89+
}, var.extra_private_subnet_tags)
9090
}
9191

9292
resource "aws_route_table" "private-rt" {

variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ variable "public_subnets" {
1616
}
1717
description = "public subnets map, availability zone map to cidr block"
1818
}
19+
20+
variable "extra_public_subnet_tags" {
21+
default = {}
22+
description = "extra tags to add to public subnet"
23+
}
1924
variable "private_subnets" {
2025
default = {
2126
a = "10.240.12.0/22"
@@ -25,6 +30,11 @@ variable "private_subnets" {
2530
description = "private subnets map, availability zone map to cidr block"
2631
}
2732

33+
variable "extra_private_subnet_tags" {
34+
default = {}
35+
description = "extra tags to add to private subnet"
36+
}
37+
2838
variable "natgateway" {
2939
default = ["a", "b", "c"]
3040
description = "nat gateway list of availability zone to spread"

0 commit comments

Comments
 (0)