@@ -21,9 +21,14 @@ locals {
21
21
# To give us a short-hand refernce to the AZ
22
22
az = data. aws_subnet . server-subnet . availability_zone
23
23
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
+
24
29
# The `name_prefix` we provide to the `iam-instance-profile` module
25
30
# 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 } "
27
32
28
33
data_volume_default = {
29
34
type = " gp2"
@@ -46,7 +51,7 @@ module "instance-profile" {
46
51
# Create a single EBS volume that can be used in a single/specific AZ, for the ASG
47
52
module "service-data" {
48
53
source = " ../persistent-ebs"
49
- name_prefix = " ${ var . name_prefix } - ${ var . name_suffix } "
54
+ name_prefix = local . name_prefix_with_az
50
55
region = var. region
51
56
az = local. az
52
57
volumes = local. data_volumes_default
@@ -72,8 +77,7 @@ module "server" {
72
77
public_ip = var. public_ip
73
78
# the prefix and suffix names are combined in
74
79
# 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
77
81
78
82
root_volume_type = var. root_volume_type
79
83
root_volume_size = var. root_volume_size
0 commit comments