Commit 8064e5d7 authored by Denis Iskandarov's avatar Denis Iskandarov Committed by Anton Babenko

Ability to append numerical suffix even to 1 instance (#70)

* ability to append numerical suffix even to 1 instance
Signed-off-by: default avatarDenis Iskandarov <d.iskandarov@gmail.com>

* include use_num_suffix in README.md
parent c92e80cb
......@@ -107,6 +107,7 @@ data "aws_ami" "ubuntu-xenial" {
| key\_name | The key name to use for the instance | string | `""` | no |
| monitoring | If true, the launched EC2 instance will have detailed monitoring enabled | string | `"false"` | no |
| name | Name to be used on all resources as prefix | string | n/a | yes |
| use\_num\_suffix | Always append numerical suffix to instance name, even if instance_count is 1 | string | `"false"` | no |
| network\_interface | Customize network interfaces to be attached at instance boot time | list | `<list>` | no |
| placement\_group | The Placement Group to start the instance in | string | `""` | no |
| private\_ip | Private IP address to associate with the instance in a VPC | string | `""` | no |
......
locals {
is_t_instance_type = "${replace(var.instance_type, "/^t[23]{1}\\..*$/", "1") == "1" ? "1" : "0"}"
instance_name = "${map("Name", (var.instance_count > 1) || (var.use_num_suffix == "true") ? format("%s-%d", var.name, count.index+1) : var.name)}"
}
######
......@@ -34,7 +35,7 @@ resource "aws_instance" "this" {
placement_group = "${var.placement_group}"
tenancy = "${var.tenancy}"
tags = "${merge(map("Name", var.instance_count > 1 ? format("%s-%d", var.name, count.index+1) : var.name), var.tags)}"
tags = "${merge(locals.instance_name, var.tags)}"
lifecycle {
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
......@@ -77,7 +78,7 @@ resource "aws_instance" "this_t2" {
cpu_credits = "${var.cpu_credits}"
}
tags = "${merge(map("Name", var.instance_count > 1 ? format("%s-%d", var.name, count.index+1) : var.name), var.tags)}"
tags = "${merge(locals.instance_name, var.tags)}"
lifecycle {
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
......
......@@ -135,3 +135,8 @@ variable "cpu_credits" {
description = "The credit option for CPU usage (unlimited or standard)"
default = "standard"
}
variable "use_num_suffix" {
description = "Always append numerical suffix to instance name, even if instance_count is 1"
default = "false"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment