Skip to content

Commit

Permalink
allow private/public subnets to be individually tagged (#1)
Browse files Browse the repository at this point in the history
Co-authored-by: Sung Kang <[email protected]>
  • Loading branch information
maxbrunet and Sung Kang committed Dec 5, 2020
1 parent af51566 commit 9a964d6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
31 changes: 31 additions & 0 deletions examples/eks-subnet-tagging/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module "vpc" {
source = "../../"

name = "my-eks-cluster"

cidr = "10.0.0.0/16"

azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
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"]
public_subnets = ["10.0.160.0/19", "10.0.192.0/19", "10.0.224.0/20", "10.0.240.0/20"]

enable_nat_gateway = true
single_nat_gateway = true

private_subnet_tags = {
global = { foo = "bar" }
0 = { "kubernetes.io/cluster/my-eks-cluster-name" = "shared" }
1 = { "kubernetes.io/cluster/my-eks-cluster-name" = "shared" }
2 = { "kubernetes.io/cluster/my-eks-cluster-name" = "shared" }
3 = { "kubernetes.io/role/internal-elb" = 1 }
4 = { "component" = "some other component"}
}

public_subnet_tags = {
global = { foo = "bar" }
0 = { "kubernetes.io/cluster/my-eks-cluster-name" = "shared" }
1 = { "kubernetes.io/cluster/my-eks-cluster-name" = "shared" }
2 = { "kubernetes.io/cluster/my-eks-cluster-name" = "shared" }
3 = { "component" = "some other component"}
}
}
2 changes: 1 addition & 1 deletion examples/network-acls/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module "vpc" {
single_nat_gateway = true

public_subnet_tags = {
Name = "overridden-name-public"
global = { Name = "overridden-name-public" }
}

tags = {
Expand Down
2 changes: 1 addition & 1 deletion examples/secondary-cidr-blocks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module "vpc" {
single_nat_gateway = true

public_subnet_tags = {
Name = "overridden-name-public"
global = { Name = "overridden-name-public"}
}

tags = {
Expand Down
18 changes: 16 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ locals {
var.tags,
var.vpc_endpoint_tags,
)

private_subnet_tags = merge(
{ "global" = {} },
{ for i in range(length(var.private_subnets)): i => {} },
var.private_subnet_tags
)

public_subnet_tags = merge(
{ "global" = {} },
{ for i in range(length(var.public_subnets)): i => {} },
var.public_subnet_tags
)
}

######
Expand Down Expand Up @@ -347,7 +359,8 @@ resource "aws_subnet" "public" {
)
},
var.tags,
var.public_subnet_tags,
local.public_subnet_tags["global"],
local.public_subnet_tags[count.index],
)
}

Expand All @@ -374,7 +387,8 @@ resource "aws_subnet" "private" {
)
},
var.tags,
var.private_subnet_tags,
local.private_subnet_tags["global"],
local.private_subnet_tags[count.index],
)
}

Expand Down
8 changes: 4 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1956,14 +1956,14 @@ variable "igw_tags" {
}

variable "public_subnet_tags" {
description = "Additional tags for the public subnets"
type = map(string)
description = "Additional tags for the public subnets. Keyed based on subnets, global tags will be applied to all subnets"
type = map(map(string))
default = {}
}

variable "private_subnet_tags" {
description = "Additional tags for the private subnets"
type = map(string)
description = "Additional tags for the private subnets. Keyed based on subnets, global tags will be applied to all subnets"
type = map(map(string))
default = {}
}

Expand Down

0 comments on commit 9a964d6

Please sign in to comment.