Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit be3222b

Browse files
committed
single-node-asg: make name_suffix optional
1 parent 1e5157d commit be3222b

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

modules/single-node-asg/main.tf

+8-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ locals {
2121
# To give us a short-hand refernce to the AZ
2222
az = data.aws_subnet.server-subnet.availability_zone
2323

24+
# with or without the suffix, eg, if suffix is empty, skip it and avoid the extra -
25+
name_prefix_with_suffix = "${var.name_prefix}-${var.name_suffix}"
26+
name_prefix_without_suffix = "${var.name_prefix}"
27+
name_prefix = "${var.name_suffix != "" ? local.name_prefix_without_suffix : local.name_prefix_with_suffix}"
28+
2429
# The `name_prefix` we provide to the `iam-instance-profile` module
2530
# The persistent-ebs module appends the AZ to the data node name, other modules don't do that
26-
name_prefix_with_az = "${var.name_prefix}-${var.name_suffix}-${local.az}"
31+
name_prefix_with_az = "${local.name_prefix}-${local.az}"
2732

2833
data_volume_default = {
2934
type = "gp2"
@@ -46,7 +51,7 @@ module "instance-profile" {
4651
# Create a single EBS volume that can be used in a single/specific AZ, for the ASG
4752
module "service-data" {
4853
source = "../persistent-ebs"
49-
name_prefix = "${var.name_prefix}-${var.name_suffix}"
54+
name_prefix = local.name_prefix_with_az
5055
region = var.region
5156
az = local.az
5257
volumes = local.data_volumes_default
@@ -72,8 +77,7 @@ module "server" {
7277
public_ip = var.public_ip
7378
# the prefix and suffix names are combined in
7479
# the `asg` module to create the full name
75-
name_prefix = var.name_prefix
76-
name_suffix = "${var.name_suffix}-${local.az}"
80+
name_prefix = local.name_prefix_with_az
7781

7882
root_volume_type = var.root_volume_type
7983
root_volume_size = var.root_volume_size

modules/single-node-asg/variables.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ variable "placement_group" {
2525
}
2626

2727
variable "name_suffix" {
28-
description = "suffix to include when naming the various resources"
28+
description = "suffix to include when naming the various resources, ignored if left as empty string"
29+
default = ""
2930
type = string
3031
}
3132

0 commit comments

Comments
 (0)