Skip to content

Commit 9a964d6

Browse files
maxbrunetSung Kang
andcommitted
allow private/public subnets to be individually tagged (#1)
Co-authored-by: Sung Kang <[email protected]>
1 parent af51566 commit 9a964d6

File tree

5 files changed

+53
-8
lines changed

5 files changed

+53
-8
lines changed

examples/eks-subnet-tagging/main.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module "vpc" {
2+
source = "../../"
3+
4+
name = "my-eks-cluster"
5+
6+
cidr = "10.0.0.0/16"
7+
8+
azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
9+
private_subnets = ["10.0.0.0/19", "10.0.32.0/19", "10.0.64.0/19", "10.0.128.0/20", "10.0.144.0/20"]
10+
public_subnets = ["10.0.160.0/19", "10.0.192.0/19", "10.0.224.0/20", "10.0.240.0/20"]
11+
12+
enable_nat_gateway = true
13+
single_nat_gateway = true
14+
15+
private_subnet_tags = {
16+
global = { foo = "bar" }
17+
0 = { "kubernetes.io/cluster/my-eks-cluster-name" = "shared" }
18+
1 = { "kubernetes.io/cluster/my-eks-cluster-name" = "shared" }
19+
2 = { "kubernetes.io/cluster/my-eks-cluster-name" = "shared" }
20+
3 = { "kubernetes.io/role/internal-elb" = 1 }
21+
4 = { "component" = "some other component"}
22+
}
23+
24+
public_subnet_tags = {
25+
global = { foo = "bar" }
26+
0 = { "kubernetes.io/cluster/my-eks-cluster-name" = "shared" }
27+
1 = { "kubernetes.io/cluster/my-eks-cluster-name" = "shared" }
28+
2 = { "kubernetes.io/cluster/my-eks-cluster-name" = "shared" }
29+
3 = { "component" = "some other component"}
30+
}
31+
}

examples/network-acls/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module "vpc" {
3939
single_nat_gateway = true
4040

4141
public_subnet_tags = {
42-
Name = "overridden-name-public"
42+
global = { Name = "overridden-name-public" }
4343
}
4444

4545
tags = {

examples/secondary-cidr-blocks/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module "vpc" {
2020
single_nat_gateway = true
2121

2222
public_subnet_tags = {
23-
Name = "overridden-name-public"
23+
global = { Name = "overridden-name-public"}
2424
}
2525

2626
tags = {

main.tf

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ locals {
2121
var.tags,
2222
var.vpc_endpoint_tags,
2323
)
24+
25+
private_subnet_tags = merge(
26+
{ "global" = {} },
27+
{ for i in range(length(var.private_subnets)): i => {} },
28+
var.private_subnet_tags
29+
)
30+
31+
public_subnet_tags = merge(
32+
{ "global" = {} },
33+
{ for i in range(length(var.public_subnets)): i => {} },
34+
var.public_subnet_tags
35+
)
2436
}
2537

2638
######
@@ -347,7 +359,8 @@ resource "aws_subnet" "public" {
347359
)
348360
},
349361
var.tags,
350-
var.public_subnet_tags,
362+
local.public_subnet_tags["global"],
363+
local.public_subnet_tags[count.index],
351364
)
352365
}
353366

@@ -374,7 +387,8 @@ resource "aws_subnet" "private" {
374387
)
375388
},
376389
var.tags,
377-
var.private_subnet_tags,
390+
local.private_subnet_tags["global"],
391+
local.private_subnet_tags[count.index],
378392
)
379393
}
380394

variables.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,14 +1956,14 @@ variable "igw_tags" {
19561956
}
19571957

19581958
variable "public_subnet_tags" {
1959-
description = "Additional tags for the public subnets"
1960-
type = map(string)
1959+
description = "Additional tags for the public subnets. Keyed based on subnets, global tags will be applied to all subnets"
1960+
type = map(map(string))
19611961
default = {}
19621962
}
19631963

19641964
variable "private_subnet_tags" {
1965-
description = "Additional tags for the private subnets"
1966-
type = map(string)
1965+
description = "Additional tags for the private subnets. Keyed based on subnets, global tags will be applied to all subnets"
1966+
type = map(map(string))
19671967
default = {}
19681968
}
19691969

0 commit comments

Comments
 (0)