Skip to content

Commit 025d3b4

Browse files
feat: Add input variable 'instance_tags' (#343)
1 parent 97ea2bf commit 025d3b4

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ No modules.
224224
| <a name="input_iam_role_use_name_prefix"></a> [iam\_role\_use\_name\_prefix](#input\_iam\_role\_use\_name\_prefix) | Determines whether the IAM role name (`iam_role_name` or `name`) is used as a prefix | `bool` | `true` | no |
225225
| <a name="input_ignore_ami_changes"></a> [ignore\_ami\_changes](#input\_ignore\_ami\_changes) | Whether changes to the AMI ID changes should be ignored by Terraform. Note - changing this value will result in the replacement of the instance | `bool` | `false` | no |
226226
| <a name="input_instance_initiated_shutdown_behavior"></a> [instance\_initiated\_shutdown\_behavior](#input\_instance\_initiated\_shutdown\_behavior) | Shutdown behavior for the instance. Amazon defaults this to stop for EBS-backed instances and terminate for instance-store instances. Cannot be set on instance-store instance | `string` | `null` | no |
227+
| <a name="input_instance_tags"></a> [instance\_tags](#input\_instance\_tags) | Additional tags for the instance | `map(string)` | `{}` | no |
227228
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | The type of instance to start | `string` | `"t3.micro"` | no |
228229
| <a name="input_ipv6_address_count"></a> [ipv6\_address\_count](#input\_ipv6\_address\_count) | A number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet | `number` | `null` | no |
229230
| <a name="input_ipv6_addresses"></a> [ipv6\_addresses](#input\_ipv6\_addresses) | Specify one or more IPv6 addresses from the range of the subnet to associate with the primary network interface | `list(string)` | `null` | no |

examples/complete/main.tf

+3-6
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,9 @@ module "ec2_cpu_options" {
414414
}
415415
]
416416

417-
tags = merge(
418-
local.tags,
419-
{
420-
Name = "${local.name}-cpu-options"
421-
}
422-
)
417+
instance_tags = { Persistence = "09:00-18:00" }
418+
419+
tags = local.tags
423420
}
424421

425422
################################################################################

main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ resource "aws_instance" "this" {
176176
delete = try(var.timeouts.delete, null)
177177
}
178178

179-
tags = merge({ "Name" = var.name }, var.tags)
179+
tags = merge({ "Name" = var.name }, var.instance_tags, var.tags)
180180
volume_tags = var.enable_volume_tags ? merge({ "Name" = var.name }, var.volume_tags) : null
181181
}
182182

@@ -344,7 +344,7 @@ resource "aws_instance" "ignore_ami" {
344344
delete = try(var.timeouts.delete, null)
345345
}
346346

347-
tags = merge({ "Name" = var.name }, var.tags)
347+
tags = merge({ "Name" = var.name }, var.instance_tags, var.tags)
348348
volume_tags = var.enable_volume_tags ? merge({ "Name" = var.name }, var.volume_tags) : null
349349

350350
lifecycle {
@@ -518,7 +518,7 @@ resource "aws_spot_instance_request" "this" {
518518
delete = try(var.timeouts.delete, null)
519519
}
520520

521-
tags = merge({ "Name" = var.name }, var.tags)
521+
tags = merge({ "Name" = var.name }, var.instance_tags, var.tags)
522522
volume_tags = var.enable_volume_tags ? merge({ "Name" = var.name }, var.volume_tags) : null
523523
}
524524

variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ variable "instance_type" {
124124
default = "t3.micro"
125125
}
126126

127+
variable "instance_tags" {
128+
description = "Additional tags for the instance"
129+
type = map(string)
130+
default = {}
131+
}
132+
127133
variable "ipv6_address_count" {
128134
description = "A number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet"
129135
type = number

wrappers/main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module "wrapper" {
2424
iam_instance_profile = try(each.value.iam_instance_profile, var.defaults.iam_instance_profile, null)
2525
instance_initiated_shutdown_behavior = try(each.value.instance_initiated_shutdown_behavior, var.defaults.instance_initiated_shutdown_behavior, null)
2626
instance_type = try(each.value.instance_type, var.defaults.instance_type, "t3.micro")
27+
instance_tags = try(each.value.instance_tags, var.defaults.instance_tags, {})
2728
ipv6_address_count = try(each.value.ipv6_address_count, var.defaults.ipv6_address_count, null)
2829
ipv6_addresses = try(each.value.ipv6_addresses, var.defaults.ipv6_addresses, null)
2930
key_name = try(each.value.key_name, var.defaults.key_name, null)

0 commit comments

Comments
 (0)