Skip to content

Commit 8064e5d

Browse files
den-isantonbabenko
authored andcommitted
Ability to append numerical suffix even to 1 instance (#70)
* ability to append numerical suffix even to 1 instance Signed-off-by: Denis Iskandarov <[email protected]> * include use_num_suffix in README.md
1 parent c92e80c commit 8064e5d

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
@@ -107,6 +107,7 @@ data "aws_ami" "ubuntu-xenial" {
107107
| key\_name | The key name to use for the instance | string | `""` | no |
108108
| monitoring | If true, the launched EC2 instance will have detailed monitoring enabled | string | `"false"` | no |
109109
| name | Name to be used on all resources as prefix | string | n/a | yes |
110+
| use\_num\_suffix | Always append numerical suffix to instance name, even if instance_count is 1 | string | `"false"` | no |
110111
| network\_interface | Customize network interfaces to be attached at instance boot time | list | `<list>` | no |
111112
| placement\_group | The Placement Group to start the instance in | string | `""` | no |
112113
| private\_ip | Private IP address to associate with the instance in a VPC | string | `""` | no |

main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
locals {
22
is_t_instance_type = "${replace(var.instance_type, "/^t[23]{1}\\..*$/", "1") == "1" ? "1" : "0"}"
3+
instance_name = "${map("Name", (var.instance_count > 1) || (var.use_num_suffix == "true") ? format("%s-%d", var.name, count.index+1) : var.name)}"
34
}
45

56
######
@@ -34,7 +35,7 @@ resource "aws_instance" "this" {
3435
placement_group = "${var.placement_group}"
3536
tenancy = "${var.tenancy}"
3637

37-
tags = "${merge(map("Name", var.instance_count > 1 ? format("%s-%d", var.name, count.index+1) : var.name), var.tags)}"
38+
tags = "${merge(locals.instance_name, var.tags)}"
3839

3940
lifecycle {
4041
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
@@ -77,7 +78,7 @@ resource "aws_instance" "this_t2" {
7778
cpu_credits = "${var.cpu_credits}"
7879
}
7980

80-
tags = "${merge(map("Name", var.instance_count > 1 ? format("%s-%d", var.name, count.index+1) : var.name), var.tags)}"
81+
tags = "${merge(locals.instance_name, var.tags)}"
8182

8283
lifecycle {
8384
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance:

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,8 @@ variable "cpu_credits" {
135135
description = "The credit option for CPU usage (unlimited or standard)"
136136
default = "standard"
137137
}
138+
139+
variable "use_num_suffix" {
140+
description = "Always append numerical suffix to instance name, even if instance_count is 1"
141+
default = "false"
142+
}

0 commit comments

Comments
 (0)