Skip to content

Commit e05d41d

Browse files
authored
feat: DA solution updates:<br>- removed kms_region variable as its now programmatically determined<br>- existing_kms_root_key_id has been replaced by existing_kms_root_key_crn<br>- existing_resource_group has been renamed to use_existing_resource_group (#178)
1 parent 77e2ed8 commit e05d41d

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

ibm_catalog.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@
5050
}
5151
]
5252
},
53+
"configuration" : [
54+
{
55+
"key": "existing_kms_root_key_crn",
56+
"required": true
57+
}
58+
],
5359
"iam_permissions": [
5460
{
5561
"role_crns": [

solutions/standard/catalogValidationValues.json.template

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"ibmcloud_api_key": $VALIDATION_APIKEY,
33
"resource_group_name": $PREFIX,
44
"tags": $TAGS,
5-
"existing_kms_instance_crn": "crn:v1:bluemix:public:hs-crypto:us-south:a/abac0df06b644a9cabc6e44f55b3880e:e6dce284-e80f-46e1-a3c1-830f7adff7a9::",
6-
"kms_region": "us-south",
5+
"existing_kms_instance_crn": $HPCS_US_SOUTH_CRN,
76
"kms_endpoint_url": "https://api.private.us-south.hs-crypto.cloud.ibm.com:8992"
87
}

solutions/standard/main.tf

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,33 @@
55
module "resource_group" {
66
source = "terraform-ibm-modules/resource-group/ibm"
77
version = "1.1.5"
8-
resource_group_name = var.existing_resource_group == false ? var.resource_group_name : null
9-
existing_resource_group_name = var.existing_resource_group == true ? var.resource_group_name : null
8+
resource_group_name = var.use_existing_resource_group == false ? var.resource_group_name : null
9+
existing_resource_group_name = var.use_existing_resource_group == true ? var.resource_group_name : null
1010
}
1111

1212
#######################################################################################################################
1313
# KMS Key
1414
#######################################################################################################################
1515

1616
locals {
17-
en_kms_key_id = var.existing_kms_root_key_id != null ? var.existing_kms_root_key_id : module.kms[0].keys[format("%s.%s", var.en_key_ring_name, var.en_key_name)].key_id
17+
parsed_existing_kms_root_key_crn = var.existing_kms_root_key_crn != null ? split(":", var.existing_kms_root_key_crn) : []
18+
existing_kms_root_key_id = length(local.parsed_existing_kms_root_key_crn) > 0 ? local.parsed_existing_kms_root_key_crn[length(local.parsed_existing_kms_root_key_crn) - 1] : null
19+
parsed_existing_kms_instance_crn = var.existing_kms_instance_crn != null ? split(":", var.existing_kms_instance_crn) : []
20+
kms_region = length(local.parsed_existing_kms_instance_crn) > 0 ? local.parsed_existing_kms_instance_crn[5] : null
21+
en_kms_key_id = local.existing_kms_root_key_id != null ? local.existing_kms_root_key_id : module.kms[0].keys[format("%s.%s", var.en_key_ring_name, var.en_key_name)].key_id
1822
}
1923

2024
# KMS root key for Event Notifications
2125
module "kms" {
2226
providers = {
2327
ibm = ibm.kms
2428
}
25-
count = var.existing_kms_root_key_id != null ? 0 : 1 # no need to create any KMS resources if passing an existing key
29+
count = var.existing_kms_root_key_crn != null ? 0 : 1 # no need to create any KMS resources if passing an existing key
2630
source = "terraform-ibm-modules/kms-all-inclusive/ibm"
2731
version = "4.8.4"
2832
resource_group_id = null # rg only needed if creating KP instance
2933
create_key_protect_instance = false
30-
region = var.kms_region
34+
region = local.kms_region
3135
existing_kms_instance_guid = var.existing_kms_instance_crn
3236
key_ring_endpoint_type = var.kms_endpoint_type
3337
key_endpoint_type = var.kms_endpoint_type

solutions/standard/provider.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ provider "ibm" {
66
provider "ibm" {
77
alias = "kms"
88
ibmcloud_api_key = var.ibmcloud_api_key
9-
region = var.kms_region
9+
region = local.kms_region
1010
}

solutions/standard/variables.tf

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ variable "ibmcloud_api_key" {
88
sensitive = true
99
}
1010

11-
variable "existing_resource_group" {
11+
variable "use_existing_resource_group" {
1212
type = bool
1313
description = "Whether to use an existing resource group."
1414
default = false
@@ -82,9 +82,9 @@ variable "existing_kms_instance_crn" {
8282
description = "The CRN of the Hyper Protect Crypto Services or Key Protect instance."
8383
}
8484

85-
variable "existing_kms_root_key_id" {
85+
variable "existing_kms_root_key_crn" {
8686
type = string
87-
description = "The Key ID of a root key, existing in the KMS instance passed in var.existing_kms_instance_crn, which will be used to encrypt the data encryption keys (DEKs) which are then used to encrypt the data. The code will create the key if one is not passed in."
87+
description = "The Key CRN of a root key, existing in the KMS instance passed in var.existing_kms_instance_crn, which will be used to encrypt the data encryption keys (DEKs) which are then used to encrypt the data. The code will create the key if one is not passed in."
8888
default = null
8989
}
9090

@@ -93,12 +93,6 @@ variable "kms_endpoint_url" {
9393
description = "The KMS endpoint URL to use when configuring KMS encryption. HPCS endpoint URL format- https://api.private.<REGION>.hs-crypto.cloud.ibm.com:<port> and KP endpoint URL format- https://<REGION>.kms.cloud.ibm.com. Only required if not passing existing key."
9494
}
9595

96-
variable "kms_region" {
97-
type = string
98-
default = "us-south"
99-
description = "The region in which KMS instance exists."
100-
}
101-
10296
variable "kms_endpoint_type" {
10397
type = string
10498
description = "The type of endpoint to be used for commincating with the KMS instance. Allowed values are: 'public' or 'private' (default). Only used if not supplying an existing root key."

tests/pr_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ func TestDAInSchematics(t *testing.T) {
128128
{Name: "resource_group_name", Value: options.Prefix, DataType: "string"},
129129
{Name: "region", Value: region, DataType: "string"},
130130
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
131-
{Name: "kms_region", Value: "us-south", DataType: "string"}, // KMS instance is in us-south
132131
{Name: "kms_endpoint_url", Value: permanentResources["hpcs_south_private_endpoint"], DataType: "string"},
133132
}
134133

0 commit comments

Comments
 (0)