Skip to content

Commit

Permalink
feat: Add input variable 'instance_tags' (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
luigidifraiawork authored Jun 28, 2023
1 parent 97ea2bf commit 025d3b4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ No modules.
| <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 |
| <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 |
| <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 |
| <a name="input_instance_tags"></a> [instance\_tags](#input\_instance\_tags) | Additional tags for the instance | `map(string)` | `{}` | no |
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | The type of instance to start | `string` | `"t3.micro"` | no |
| <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 |
| <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 |
Expand Down
9 changes: 3 additions & 6 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,9 @@ module "ec2_cpu_options" {
}
]

tags = merge(
local.tags,
{
Name = "${local.name}-cpu-options"
}
)
instance_tags = { Persistence = "09:00-18:00" }

tags = local.tags
}

################################################################################
Expand Down
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ resource "aws_instance" "this" {
delete = try(var.timeouts.delete, null)
}

tags = merge({ "Name" = var.name }, var.tags)
tags = merge({ "Name" = var.name }, var.instance_tags, var.tags)
volume_tags = var.enable_volume_tags ? merge({ "Name" = var.name }, var.volume_tags) : null
}

Expand Down Expand Up @@ -344,7 +344,7 @@ resource "aws_instance" "ignore_ami" {
delete = try(var.timeouts.delete, null)
}

tags = merge({ "Name" = var.name }, var.tags)
tags = merge({ "Name" = var.name }, var.instance_tags, var.tags)
volume_tags = var.enable_volume_tags ? merge({ "Name" = var.name }, var.volume_tags) : null

lifecycle {
Expand Down Expand Up @@ -518,7 +518,7 @@ resource "aws_spot_instance_request" "this" {
delete = try(var.timeouts.delete, null)
}

tags = merge({ "Name" = var.name }, var.tags)
tags = merge({ "Name" = var.name }, var.instance_tags, var.tags)
volume_tags = var.enable_volume_tags ? merge({ "Name" = var.name }, var.volume_tags) : null
}

Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ variable "instance_type" {
default = "t3.micro"
}

variable "instance_tags" {
description = "Additional tags for the instance"
type = map(string)
default = {}
}

variable "ipv6_address_count" {
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"
type = number
Expand Down
1 change: 1 addition & 0 deletions wrappers/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module "wrapper" {
iam_instance_profile = try(each.value.iam_instance_profile, var.defaults.iam_instance_profile, null)
instance_initiated_shutdown_behavior = try(each.value.instance_initiated_shutdown_behavior, var.defaults.instance_initiated_shutdown_behavior, null)
instance_type = try(each.value.instance_type, var.defaults.instance_type, "t3.micro")
instance_tags = try(each.value.instance_tags, var.defaults.instance_tags, {})
ipv6_address_count = try(each.value.ipv6_address_count, var.defaults.ipv6_address_count, null)
ipv6_addresses = try(each.value.ipv6_addresses, var.defaults.ipv6_addresses, null)
key_name = try(each.value.key_name, var.defaults.key_name, null)
Expand Down

0 comments on commit 025d3b4

Please sign in to comment.