Skip to content

Commit 00970d7

Browse files
committed
feat: add eks specific tags
1 parent 097b48c commit 00970d7

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,46 @@ As this module was originalyl intended to create 1 vpc with 1 cidr range for man
204204
> terragrunt import 'module.vpc.aws_vpc_ipv4_cidr_block_association.this[0]' vpc-cidr-assoc-xxx
205205
> terragrunt import 'module.vpc.aws_internet_gateway.this[0]' igw-xxx
206206
207+
### EKS Subnet-Specific Tags
208+
209+
With the introduction of subnet-specific EKS tag variables, you can now apply different tags to different subnet types. This is useful when you need specific tags for different subnet types for EKS cluster requirements or organizational purposes.
210+
211+
```hcl
212+
module "vpc" {
213+
vpc_cidr = "172.1.1.0/25"
214+
215+
# General EKS cluster tags applied to all subnets
216+
eks_cluster_tags = {
217+
"kubernetes.io/cluster/my-cluster" = "shared"
218+
}
219+
220+
# Public subnet specific EKS tags
221+
eks_public_subnet_tags = {
222+
"kubernetes.io/cluster/my-cluster" = "owned"
223+
"Environment" = "production"
224+
}
225+
226+
# Private subnet specific EKS tags
227+
eks_private_subnet_tags = {
228+
"kubernetes.io/cluster/my-cluster" = "owned"
229+
"Tier" = "application"
230+
}
231+
232+
# Intra subnet specific EKS tags
233+
eks_intra_subnet_tags = {
234+
"Tier" = "management"
235+
}
236+
237+
public_subnets = ["172.1.1.0/27"]
238+
private_subnets = ["172.1.1.32/27"]
239+
intranet_subnets = ["172.1.1.64/27"]
240+
database_subnets = ["172.1.1.96/27"]
241+
number_of_azs = 2
242+
}
243+
```
244+
245+
**Note**: The subnet-specific tags are merged with the general `eks_cluster_tags`, so you don't need to repeat common tags across all subnet types.
246+
207247
<!-- BEGIN_TF_DOCS -->
208248
## Requirements
209249

@@ -359,6 +399,10 @@ No requirements.
359399
| <a name="input_default_vpc_name"></a> [default\_vpc\_name](#input\_default\_vpc\_name) | Name to be used on the Default VPC | `string` | `null` | no |
360400
| <a name="input_default_vpc_tags"></a> [default\_vpc\_tags](#input\_default\_vpc\_tags) | Additional tags for the Default VPC | `map(string)` | `{}` | no |
361401
| <a name="input_eks_cluster_tags"></a> [eks\_cluster\_tags](#input\_eks\_cluster\_tags) | List of tags that EKS will create, but also added to VPC for persistency across terraform applies | `map(any)` | `{}` | no |
402+
| <a name="input_eks_database_subnet_tags"></a> [eks\_database\_subnet\_tags](#input\_eks\_database\_subnet\_tags) | Additional EKS-specific tags to apply to database subnets only | `map(any)` | `{}` | no |
403+
| <a name="input_eks_intra_subnet_tags"></a> [eks\_intra\_subnet\_tags](#input\_eks\_intra\_subnet\_tags) | Additional EKS-specific tags to apply to intra subnets only | `map(any)` | `{}` | no |
404+
| <a name="input_eks_private_subnet_tags"></a> [eks\_private\_subnet\_tags](#input\_eks\_private\_subnet\_tags) | Additional EKS-specific tags to apply to private subnets only | `map(any)` | `{}` | no |
405+
| <a name="input_eks_public_subnet_tags"></a> [eks\_public\_subnet\_tags](#input\_eks\_public\_subnet\_tags) | Additional EKS-specific tags to apply to public subnets only | `map(any)` | `{}` | no |
362406
| <a name="input_enable_flow_log"></a> [enable\_flow\_log](#input\_enable\_flow\_log) | Whether or not to enable VPC Flow Logs | `bool` | `false` | no |
363407
| <a name="input_enable_nat_gateway"></a> [enable\_nat\_gateway](#input\_enable\_nat\_gateway) | Should be true if you want to provision NAT Gateways for each of your private networks | `bool` | `true` | no |
364408
| <a name="input_firewall_dedicated_network_acl"></a> [firewall\_dedicated\_network\_acl](#input\_firewall\_dedicated\_network\_acl) | Whether to use dedicated network ACL (not default) and custom rules for firewall subnets | `bool` | `false` | no |

main.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ locals {
1414
vpc_tags = merge(var.vpc_tags)
1515

1616
vpc_flow_log_name_chunks = split(":", module.vpc.vpc_flow_log_destination_arn)
17-
vpc_flow_log_name = local.vpc_flow_log_name_chunks[length(local.vpc_flow_log_name_chunks) - 1]
17+
vpc_flow_log_name = local.vpc_flow_log_name_chunks[length(local.vpc_flow_log_name_chunks) - 1]
1818
}
1919

2020
# creates the elastic IPs which the NAT gateways are allocated
@@ -41,6 +41,7 @@ module "vpc" {
4141

4242
public_subnet_tags = merge(
4343
var.eks_cluster_tags,
44+
var.eks_public_subnet_tags,
4445
{
4546
"kubernetes.io/role/elb" = "1",
4647
"AccessType" = "internet ingress/egress"
@@ -77,6 +78,7 @@ module "vpc" {
7778

7879
private_subnet_tags = merge(
7980
var.eks_cluster_tags,
81+
var.eks_private_subnet_tags,
8082
{
8183
"kubernetes.io/role/internal-elb" = "1",
8284
"AccessType" = "internet egress"
@@ -91,6 +93,7 @@ module "vpc" {
9193

9294
intra_subnet_tags = merge(
9395
var.eks_cluster_tags,
96+
var.eks_intra_subnet_tags,
9497
{
9598
"AccessType" = "intranet"
9699
}
@@ -237,7 +240,7 @@ resource "aws_security_group" "allow_http_https_outgoing" {
237240
}
238241

239242
#######################
240-
# Flow Logs
243+
# Flow Logs
241244
#######################
242245

243246
resource "aws_cloudwatch_log_subscription_filter" "flow_log" {
@@ -248,4 +251,4 @@ resource "aws_cloudwatch_log_subscription_filter" "flow_log" {
248251
filter_pattern = each.value.filter_pattern
249252
destination_arn = each.value.destination_arn
250253
distribution = each.value.distribution
251-
}
254+
}

variables.tf

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ variable "eks_cluster_tags" {
5555
default = {}
5656
}
5757

58+
variable "eks_public_subnet_tags" {
59+
description = "Additional EKS-specific tags to apply to public subnets only"
60+
type = map(any)
61+
default = {}
62+
}
63+
64+
variable "eks_private_subnet_tags" {
65+
description = "Additional EKS-specific tags to apply to private subnets only"
66+
type = map(any)
67+
default = {}
68+
}
69+
70+
variable "eks_intra_subnet_tags" {
71+
description = "Additional EKS-specific tags to apply to intra subnets only"
72+
type = map(any)
73+
default = {}
74+
}
75+
5876
variable "number_of_azs" {
5977
description = "Determines number of availability zones to use in the region"
6078
default = 2
@@ -647,4 +665,4 @@ variable "default_network_acl_egress" {
647665
ipv6_cidr_block = "::/0"
648666
},
649667
]
650-
}
668+
}

0 commit comments

Comments
 (0)