From db4859276df37837376823fd373a878f57891f03 Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Fri, 21 Nov 2025 15:44:55 +0530 Subject: [PATCH] feat: ability to add tags on ec2 instances this is useful for adding custom tags on instances to tweak the AWS firewall rules which apply to them Signed-off-by: Ameya Shenoy --- modules/nomad-clients/ec2.tf | 15 +++++++++------ modules/nomad-clients/launch_template.tf | 9 ++++++--- modules/nomad-clients/variables.tf | 6 ++++++ modules/nomad-servers/launch_template.tf | 9 ++++++--- modules/nomad-servers/variables.tf | 6 ++++++ 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/modules/nomad-clients/ec2.tf b/modules/nomad-clients/ec2.tf index ec05db6..28669fe 100644 --- a/modules/nomad-clients/ec2.tf +++ b/modules/nomad-clients/ec2.tf @@ -32,12 +32,15 @@ resource "aws_instance" "nomad_client" { user_data_base64 = base64encode(data.cloudinit_config.config.rendered) - tags = { - Name = "${var.client_name}-${count.index + 1}" - role = "nomad-client" - nomad_client = var.client_name - nomad_ec2_join = var.nomad_join_tag_value - } + tags = merge( + { + Name = "${var.client_name}-${count.index + 1}" + role = "nomad-client" + nomad_client = var.client_name + nomad_ec2_join = var.nomad_join_tag_value + }, + var.ec2_tags + ) lifecycle { create_before_destroy = true diff --git a/modules/nomad-clients/launch_template.tf b/modules/nomad-clients/launch_template.tf index 0e4c04e..9211d40 100644 --- a/modules/nomad-clients/launch_template.tf +++ b/modules/nomad-clients/launch_template.tf @@ -40,9 +40,12 @@ resource "aws_launch_template" "nomad_client" { tag_specifications { resource_type = "instance" - tags = { - Name = var.client_name - } + tags = merge( + { + Name = var.client_name + }, + var.ec2_tags + ) } tag_specifications { diff --git a/modules/nomad-clients/variables.tf b/modules/nomad-clients/variables.tf index e0ac4ce..96178f8 100644 --- a/modules/nomad-clients/variables.tf +++ b/modules/nomad-clients/variables.tf @@ -71,6 +71,12 @@ variable "ebs_tags" { default = {} } +variable "ec2_tags" { + description = "A map of custom tags to be assigned to the EC2 instances" + type = map(string) + default = {} +} + variable "ebs_volume_type" { description = "The type of EBS volume (gp2, gp3, io1, io2, sc1, st1)" type = string diff --git a/modules/nomad-servers/launch_template.tf b/modules/nomad-servers/launch_template.tf index 513f4b7..be39838 100644 --- a/modules/nomad-servers/launch_template.tf +++ b/modules/nomad-servers/launch_template.tf @@ -38,9 +38,12 @@ resource "aws_launch_template" "nomad_server" { tag_specifications { resource_type = "instance" - tags = { - Name = "${var.cluster_name}-server" - } + tags = merge( + { + Name = "${var.cluster_name}-server" + }, + var.ec2_tags + ) } tag_specifications { diff --git a/modules/nomad-servers/variables.tf b/modules/nomad-servers/variables.tf index 29811d9..c3c0e9c 100644 --- a/modules/nomad-servers/variables.tf +++ b/modules/nomad-servers/variables.tf @@ -75,6 +75,12 @@ variable "ebs_tags" { default = {} } +variable "ec2_tags" { + description = "A map of additional tags to apply to the EC2 instances" + type = map(string) + default = {} +} + variable "ebs_encryption" { description = "Enable EBS encryption" type = bool