Skip to content

Commit e66e0d4

Browse files
authored
feat: added prefix as an optional input for the DA solution (#181)
1 parent 81f63d3 commit e66e0d4

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

common-dev-assets

solutions/secure/main.tf

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
1+
#######################################################################################################################
2+
# Local Variables
3+
#######################################################################################################################
4+
15
locals {
26
existing_kms_instance_crn_split = var.existing_kms_instance_crn != null ? split(":", var.existing_kms_instance_crn) : null
37
existing_kms_instance_guid = var.existing_kms_instance_crn != null ? element(local.existing_kms_instance_crn_split, length(local.existing_kms_instance_crn_split) - 3) : null
48
existing_kms_instance_region = var.existing_kms_instance_crn != null ? element(local.existing_kms_instance_crn_split, length(local.existing_kms_instance_crn_split) - 5) : null
9+
10+
elasticsearch_key_name = var.prefix != null ? "${var.prefix}-${var.elasticsearch_key_name}" : var.elasticsearch_key_name
11+
elasticsearch_key_ring_name = var.prefix != null ? "${var.prefix}-${var.elasticsearch_key_ring_name}" : var.elasticsearch_key_ring_name
12+
13+
kms_key_crn = var.existing_kms_key_crn != null ? var.existing_kms_key_crn : module.kms[0].keys[format("%s.%s", local.elasticsearch_key_ring_name, local.elasticsearch_key_name)].crn
514
}
615

16+
#######################################################################################################################
17+
# Resource Group
18+
#######################################################################################################################
19+
720
module "resource_group" {
821
source = "terraform-ibm-modules/resource-group/ibm"
922
version = "1.1.5"
10-
resource_group_name = var.existing_resource_group == false ? var.resource_group_name : null
23+
resource_group_name = var.existing_resource_group == false ? (var.prefix != null ? "${var.prefix}-${var.resource_group_name}" : var.resource_group_name) : null
1124
existing_resource_group_name = var.existing_resource_group == true ? var.resource_group_name : null
1225
}
1326

27+
#######################################################################################################################
1428
# KMS root key for Elasticsearch
29+
#######################################################################################################################
30+
1531
module "kms" {
1632
providers = {
1733
ibm = ibm.kms
@@ -26,12 +42,12 @@ module "kms" {
2642
key_endpoint_type = var.kms_endpoint_type
2743
keys = [
2844
{
29-
key_ring_name = var.elasticsearch_key_ring_name
45+
key_ring_name = local.elasticsearch_key_ring_name
3046
existing_key_ring = false
3147
force_delete_key_ring = true
3248
keys = [
3349
{
34-
key_name = var.elasticsearch_key_name
50+
key_name = local.elasticsearch_key_name
3551
standard_key = false
3652
rotation_interval_month = 3
3753
dual_auth_delete_enabled = false
@@ -42,14 +58,14 @@ module "kms" {
4258
]
4359
}
4460

45-
locals {
46-
kms_key_crn = var.existing_kms_key_crn != null ? var.existing_kms_key_crn : module.kms[0].keys[format("%s.%s", var.elasticsearch_key_ring_name, var.elasticsearch_key_name)].crn
47-
}
61+
#######################################################################################################################
62+
# Elasticsearch
63+
#######################################################################################################################
4864

4965
module "elasticsearch" {
5066
source = "../../modules/fscloud"
5167
resource_group_id = module.resource_group.resource_group_id
52-
name = var.name
68+
name = var.prefix != null ? "${var.prefix}-${var.name}" : var.name
5369
region = var.region
5470
plan = var.plan
5571
skip_iam_authorization_policy = var.skip_iam_authorization_policy

solutions/secure/variables.tf

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@ variable "existing_resource_group" {
1111

1212
variable "resource_group_name" {
1313
type = string
14-
description = "The name of a new or an existing resource group in which to provision the Databases for Elasicsearch in."
14+
description = "The name of a new or an existing resource group in which to provision the Databases for Elasicsearch in. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
15+
}
16+
17+
variable "prefix" {
18+
type = string
19+
description = "Prefix to add to all resources created by this solution."
20+
default = null
1521
}
1622

1723
variable "name" {
18-
description = "The name of the Elasticsearch instance"
1924
type = string
25+
description = "The name of the Databases for Elasticsearch instance. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
26+
default = "elasticsearch"
2027
}
2128

2229
variable "region" {
@@ -129,13 +136,13 @@ variable "skip_iam_authorization_policy" {
129136
variable "elasticsearch_key_ring_name" {
130137
type = string
131138
default = "elasticsearch-key-ring"
132-
description = "The name to give the Key Ring which will be created for the Elasticsearch Key. Not used if supplying an existing Key."
139+
description = "The name to give the key ring that is created for the Databases for Elasticsearch key. Not used if `existing_kms_key_crn` is specified. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
133140
}
134141

135142
variable "elasticsearch_key_name" {
136143
type = string
137144
default = "elasticsearch-key"
138-
description = "The name to give the Key which will be created for the Elasticsearch. Not used if supplying an existing Key."
145+
description = "The name to give the key that is created for the Databases for Elasticsearch key. Not used if `existing_kms_key_crn` is specified. If a `prefix` input variable is specified, it is added to this name in the `<prefix>-value` format."
139146
}
140147

141148
variable "auto_scaling" {

tests/pr_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func setupOptionsSecureSolution(t *testing.T, prefix string) *testhelper.TestOpt
9393
"existing_kms_instance_crn": permanentResources["hpcs_south_crn"],
9494
"kms_endpoint_type": "public",
9595
"resource_group_name": options.Prefix,
96-
"name": options.Prefix,
96+
"prefix": options.Prefix,
9797
}
9898

9999
return options

0 commit comments

Comments
 (0)