Skip to content

Commit f8419a8

Browse files
author
Vladimir Andrijevikj
committed
Add tags to EKS-related subnets to support discovery for ELB
https://aws.amazon.com/premiumsupport/knowledge-center/eks-vpc-subnet-discovery/
1 parent 376c595 commit f8419a8

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

aws/eks/main.tf

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
locals {
2-
tags = merge({ Name = var.name }, var.tags)
2+
elb_discovery_tag = var.uses_nat_gateway ? "kubernetes.io/role/internal-elb" : "kubernetes.io/role/elb"
3+
tags = merge({ Name = var.name }, var.tags)
4+
5+
subnet_tags = merge(local.tags, {
6+
(local.elb_discovery_tag) = true,
7+
"kubernetes.io/cluster/${var.name}" = "shared"
8+
})
39
}
410

511
module "eks-vpc" {
@@ -35,17 +41,10 @@ module "eks-subnets" {
3541
source = "../vpc/subnets"
3642

3743
exclude_names = var.subnet_module.exclude_names
38-
netnum_offset = var.subnet_module.netnum_offset
39-
4044
internet_gateway_id = module.eks-vpc.internet_gateway_id
41-
nat_gateway_id = var.uses_nat_gateway ? module.eks-vpc-nat-gateway[0].nat_gateway_id : 0
42-
43-
tags = merge(
44-
local.tags,
45-
{
46-
"kubernetes.io/cluster/${var.name}" = "shared"
47-
},
48-
)
45+
nat_gateway_id = var.uses_nat_gateway ? module.eks-vpc-nat-gateway[0].nat_gateway_id : 0
46+
netnum_offset = var.subnet_module.netnum_offset
47+
tags = local.subnet_tags
4948
vpc_id = module.eks-vpc.vpc_id
5049
}
5150

aws/nat_gateway/main.tf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
locals {
2+
subnet_tags = merge(var.tags, { "kubernetes.io/role/elb" = true })
3+
}
4+
15
# Create subnets for use by the LoadBalancer for ingress
26
# And use the first of these subnets for the NAT Gateway
37

@@ -18,14 +22,14 @@ resource "aws_subnet" "mod" {
1822
var.subnet_cidr_netnum_offset + count.index + 1,
1923
)
2024
map_public_ip_on_launch = true
21-
tags = var.tags
25+
tags = local.subnet_tags
2226
vpc_id = var.vpc_id
2327
}
2428

2529
# ElasticIP address for use with the NAT Gateway
2630
resource "aws_eip" "nat-gw-eip" {
27-
vpc = true
28-
tags = var.tags
31+
vpc = true
32+
tags = var.tags
2933
}
3034

3135
# NAT Gateway in the first subnet

0 commit comments

Comments
 (0)