Skip to content

Commit 3143486

Browse files
committed
override name tag if required
1 parent f960d95 commit 3143486

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ No modules.
6565
| <a name="input_ami"></a> [ami](#input\_ami) | Specify an AMI to run, if not it will use the latest Amazon Linux, or Windows Server image. | `string` | `""` | no |
6666
| <a name="input_associate_public_ip_address"></a> [associate\_public\_ip\_address](#input\_associate\_public\_ip\_address) | Assign public IP to the instance. | `bool` | `true` | no |
6767
| <a name="input_comment"></a> [comment](#input\_comment) | Comment tag to add to all resources | `string` | `""` | no |
68+
| <a name="input_instance_name_override"></a> [instance\_name\_override](#input\_instance\_name\_override) | Override the name tag provided to the instance. default: <username>-tmp-instance-<random string> | `string` | `null` | no |
6869
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | AWS instance type to create | `string` | `"t3.nano"` | no |
6970
| <a name="input_key_name"></a> [key\_name](#input\_key\_name) | SSH key pair to use | `string` | `""` | no |
7071
| <a name="input_subnet_id"></a> [subnet\_id](#input\_subnet\_id) | Subnet to create the instance in | `string` | n/a | yes |

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ resource "aws_instance" "instance" {
122122
tags = merge(
123123
local.common_tags,
124124
{
125-
"Name" : "${local.username}-tmp-instance-${random_string.module_suffix.result}"
125+
"Name" : var.instance_name_override != null ? "${var.instance_name_override}-${random_string.module_suffix.result}" : "${local.username}-tmp-instance-${random_string.module_suffix.result}"
126126
}
127127
)
128128
volume_tags = {}
@@ -167,4 +167,4 @@ data "aws_iam_policy_document" "assume_policy" {
167167
identifiers = ["ec2.amazonaws.com"]
168168
}
169169
}
170-
}
170+
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ variable "additional_tags" {
7272
default = {}
7373
}
7474

75+
variable "instance_name_override" {
76+
type = string
77+
description = "Override the name tag provided to the instance. default: <username>-tmp-instance-<random string>"
78+
default = null
79+
}
80+
7581
variable "additional_user_data" {
7682
type = string
7783
description = "Additional code to be added to the user_data.sh script"

0 commit comments

Comments
 (0)