Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

Commit 1832bf1

Browse files
authored
fix: fixed bug related to KMS parsing (#242)
1 parent d1982cd commit 1832bf1

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

ibm_catalog.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,21 @@
311311
},
312312
{
313313
"key": "scc_workload_protection_access_tags"
314+
},
315+
{
316+
"key": "existing_activity_tracker_crn"
317+
},
318+
{
319+
"key": "ibmcloud_kms_api_key"
320+
},
321+
{
322+
"key": "scc_en_email_list"
323+
},
324+
{
325+
"key": "scc_en_from_email"
326+
},
327+
{
328+
"key": "scc_en_reply_to_email"
314329
}
315330
],
316331
"iam_permissions": [

solutions/instances/main.tf

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ locals {
88
# tflint-ignore: terraform_unused_declarations
99
validate_cos_inputs = var.existing_scc_cos_bucket_name != null && var.existing_scc_cos_kms_key_crn != null ? tobool("A value should not be passed for 'existing_scc_cos_kms_key_crn' when passing a value for 'existing_scc_cos_bucket_name'. A key is only needed when creating a new COS bucket.") : true
1010
# tflint-ignore: terraform_unused_declarations
11+
validate_more_cos_inputs = var.existing_scc_cos_bucket_name != null && var.existing_cos_instance_crn == null ? tobool("A value for 'existing_cos_instance_crn' must be passed if 'existing_scc_cos_bucket_name' is passed in.") : true
12+
# tflint-ignore: terraform_unused_declarations
1113
validate_auth_inputs = !var.skip_scc_cos_auth_policy && var.existing_cos_instance_crn == null && var.existing_scc_cos_bucket_name != null ? tobool("A value must be passed for 'existing_cos_instance_crn' in order to create auth policy.") : true
1214
# tflint-ignore: terraform_unused_declarations
1315
validate_en_integration = var.existing_en_crn != null && var.en_source_name == null ? tobool("When passing a value for 'existing_en_crn', a value must also be passed for 'en_source_name'.") : false
@@ -36,7 +38,7 @@ module "existing_kms_crn_parser" {
3638
}
3739

3840
module "existing_kms_key_crn_parser" {
39-
count = var.existing_scc_cos_kms_key_crn != null || var.existing_kms_instance_crn != null ? 1 : 0
41+
count = var.existing_scc_cos_kms_key_crn != null || local.use_kms_module ? 1 : 0
4042
source = "terraform-ibm-modules/common-utilities/ibm//modules/crn-parser"
4143
version = "1.1.0"
4244
crn = var.existing_scc_cos_kms_key_crn != null ? var.existing_scc_cos_kms_key_crn : module.kms[0].keys[format("%s.%s", local.scc_cos_key_ring_name, local.scc_cos_key_name)].crn
@@ -58,9 +60,13 @@ locals {
5860
scc_instance_name = try("${local.prefix}-${var.scc_instance_name}", var.scc_instance_name)
5961
scc_workload_protection_instance_name = try("${local.prefix}-${var.scc_workload_protection_instance_name}", var.scc_workload_protection_instance_name)
6062
scc_workload_protection_resource_key_name = try("${local.prefix}-${var.scc_workload_protection_instance_name}-key", "${var.scc_workload_protection_instance_name}-key")
61-
scc_cos_bucket_name = try("${local.prefix}-${var.scc_cos_bucket_name}", var.scc_cos_bucket_name)
63+
# bucket name to be passed to the COS module to create a bucket
64+
created_scc_cos_bucket_name = try("${local.prefix}-${var.scc_cos_bucket_name}", var.scc_cos_bucket_name)
65+
# Final COS bucket name - either passed in or after being created by COS
66+
scc_cos_bucket_name = var.existing_scc_cos_bucket_name != null ? var.existing_scc_cos_bucket_name : local.create_cross_account_auth_policy ? module.buckets[0].buckets[local.created_scc_cos_bucket_name].bucket_name : module.cos[0].buckets[local.created_scc_cos_bucket_name].bucket_name
6267

6368
create_cross_account_auth_policy = !var.skip_cos_kms_auth_policy && var.ibmcloud_kms_api_key == null ? false : (data.ibm_iam_account_settings.iam_account_settings.account_id != module.existing_kms_crn_parser[0].account_id)
69+
use_kms_module = !(var.existing_scc_cos_kms_key_crn != null || var.existing_scc_cos_bucket_name != null || var.existing_scc_instance_crn != null)
6470
}
6571

6672
# Create IAM Authorization Policy to allow COS to access KMS for the encryption key, if cross account KMS is passed in
@@ -116,7 +122,7 @@ module "kms" {
116122
providers = {
117123
ibm = ibm.kms
118124
}
119-
count = var.existing_scc_cos_kms_key_crn != null || var.existing_scc_cos_bucket_name != null || var.existing_scc_instance_crn != null ? 0 : 1 # no need to create any KMS resources if passing an existing key or bucket, or SCC instance
125+
count = local.use_kms_module ? 1 : 0 # no need to create any KMS resources if passing an existing key or bucket, or SCC instance
120126
source = "terraform-ibm-modules/kms-all-inclusive/ibm"
121127
version = "4.19.5"
122128
create_key_protect_instance = false
@@ -155,12 +161,11 @@ module "existing_cos_crn_parser" {
155161
locals {
156162
scc_cos_kms_key_crn = var.existing_scc_instance_crn == null ? var.existing_scc_cos_bucket_name != null ? null : var.existing_scc_cos_kms_key_crn != null ? var.existing_scc_cos_kms_key_crn : module.kms[0].keys[format("%s.%s", local.scc_cos_key_ring_name, local.scc_cos_key_name)].crn : null
157163
cos_instance_crn = var.existing_scc_instance_crn == null ? var.existing_cos_instance_crn != null ? var.existing_cos_instance_crn : module.cos[0].cos_instance_crn : null
158-
cos_bucket_name = var.existing_scc_instance_crn == null ? var.existing_scc_cos_bucket_name != null ? var.existing_scc_cos_bucket_name : local.create_cross_account_auth_policy ? module.buckets[0].buckets[local.scc_cos_bucket_name].bucket_name : module.cos[0].buckets[local.scc_cos_bucket_name].bucket_name : null
159164
cos_instance_guid = var.existing_scc_instance_crn == null ? var.existing_cos_instance_crn != null ? module.existing_cos_crn_parser[0].service_instance : module.cos[0].cos_instance_guid : null
160165
bucket_config = [{
161166
access_tags = var.scc_cos_bucket_access_tags
162167
add_bucket_name_suffix = var.add_bucket_name_suffix
163-
bucket_name = local.scc_cos_bucket_name
168+
bucket_name = local.created_scc_cos_bucket_name
164169
kms_encryption_enabled = true
165170
kms_guid = local.existing_kms_guid
166171
kms_key_crn = local.scc_cos_kms_key_crn
@@ -242,7 +247,7 @@ module "scc" {
242247
region = local.scc_instance_region
243248
instance_name = local.scc_instance_name
244249
plan = var.scc_service_plan
245-
cos_bucket = local.cos_bucket_name
250+
cos_bucket = local.scc_cos_bucket_name
246251
cos_instance_crn = local.cos_instance_crn
247252
en_instance_crn = var.existing_en_crn
248253
en_source_name = var.en_source_name

solutions/instances/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ output "scc_cos_kms_key_crn" {
8787

8888
output "scc_cos_bucket_name" {
8989
description = "SCC COS bucket name"
90-
value = var.existing_scc_instance_crn == null ? var.existing_scc_cos_bucket_name != null ? var.existing_scc_cos_bucket_name : local.create_cross_account_auth_policy ? module.buckets[0].buckets[local.scc_cos_bucket_name].bucket_name : module.cos[0].buckets[local.scc_cos_bucket_name].bucket_name : null
90+
value = var.existing_scc_instance_crn == null ? local.scc_cos_bucket_name : null
9191
}
9292

9393
output "scc_cos_bucket_config" {
9494
description = "List of buckets created"
95-
value = var.existing_scc_instance_crn == null ? var.existing_scc_cos_bucket_name != null ? null : local.create_cross_account_auth_policy ? module.buckets[0].buckets[local.scc_cos_bucket_name] : module.cos[0].buckets[local.scc_cos_bucket_name] : null
95+
value = var.existing_scc_instance_crn == null ? var.existing_scc_cos_bucket_name != null ? null : local.create_cross_account_auth_policy ? module.buckets[0].buckets[local.created_scc_cos_bucket_name] : module.cos[0].buckets[local.created_scc_cos_bucket_name] : null
9696
}
9797

9898
output "scc_cos_instance_id" {

tests/pr_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ func TestRunExistingResourcesInstances(t *testing.T) {
198198
"existing_cos_instance_crn": terraform.Output(t, existingTerraformOptions, "cos_crn"),
199199
"management_endpoint_type_for_bucket": "public",
200200
"provider_visibility": "public",
201-
"existing_en_crn": terraform.Output(t, existingTerraformOptions, "en_crn"),
202-
"en_source_name": prefix, // This name must be unique per SCC instance that is integrated with the Event Notifications instance.
201+
// Temporarily removed because of provider issue: https://github.com/IBM-Cloud/terraform-provider-ibm/issues/5890
202+
// "existing_en_crn": terraform.Output(t, existingTerraformOptions, "en_crn"),
203+
// "en_source_name": prefix, // This name must be unique per SCC instance that is integrated with the Event Notifications instance.
203204
},
204205
})
205206

0 commit comments

Comments
 (0)