Skip to content

Commit 782ce09

Browse files
committed
fix unit tests
1 parent f2dcabf commit 782ce09

File tree

4 files changed

+66
-32
lines changed

4 files changed

+66
-32
lines changed

solutions/fully-configurable/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ When `existing_en_instance_crn` is passed, this solution ignores ALL other input
2929

3030
| Name | Source | Version |
3131
|------|--------|---------|
32-
| <a name="module_cos"></a> [cos](#module\_cos) | terraform-ibm-modules/cos/ibm | 8.21.8 |
32+
| <a name="module_cos_buckets"></a> [cos\_buckets](#module\_cos\_buckets) | terraform-ibm-modules/cos/ibm//modules/buckets | 8.19.2 |
3333
| <a name="module_cos_kms_key_crn_parser"></a> [cos\_kms\_key\_crn\_parser](#module\_cos\_kms\_key\_crn\_parser) | terraform-ibm-modules/common-utilities/ibm//modules/crn-parser | 1.1.0 |
3434
| <a name="module_event_notifications"></a> [event\_notifications](#module\_event\_notifications) | ../.. | n/a |
3535
| <a name="module_existing_cos_crn_parser"></a> [existing\_cos\_crn\_parser](#module\_existing\_cos\_crn\_parser) | terraform-ibm-modules/common-utilities/ibm//modules/crn-parser | 1.1.0 |

solutions/fully-configurable/main.tf

+30-22
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ locals {
8888
}
8989

9090
module "kms" {
91-
count = var.existing_event_notifications_instance_crn == null && var.kms_encryption_enabled && var.existing_kms_root_key_crn == null ? 1 : 0
91+
providers = {
92+
ibm = ibm.kms
93+
}
94+
count = var.kms_encryption_enabled && var.existing_kms_root_key_crn == null ? 1 : 0
9295
source = "terraform-ibm-modules/kms-all-inclusive/ibm"
9396
version = "4.19.5"
9497
create_key_protect_instance = false
@@ -206,30 +209,35 @@ locals {
206209
create_cos_bucket = !var.enable_collecting_failed_events || var.existing_event_notifications_instance_crn != null ? false : true
207210
# determine COS details
208211
cos_bucket_name = var.existing_event_notifications_instance_crn == null && !var.enable_collecting_failed_events ? null : local.create_cos_bucket ? try("${local.prefix}-${var.cos_bucket_name}", var.cos_bucket_name) : null
209-
cos_bucket_name_with_suffix = var.existing_event_notifications_instance_crn == null && var.enable_collecting_failed_events ? module.cos[0].bucket_name : null
212+
cos_bucket_name_with_suffix = var.existing_event_notifications_instance_crn == null && var.enable_collecting_failed_events ? module.cos_buckets[0].buckets[local.cos_bucket_name].bucket_name : null
210213
cos_bucket_region = var.existing_event_notifications_instance_crn == null && var.cos_bucket_region != null && var.cos_bucket_region != "" ? var.cos_bucket_region : var.region
211-
cos_instance_guid = var.existing_event_notifications_instance_crn == null ? (var.existing_cos_instance_crn == null ? (length(module.cos) > 0 ? module.cos[0].cos_instance_guid : null) : module.existing_cos_crn_parser[0].service_instance) : null
212-
cos_bucket_endpoint = var.existing_event_notifications_instance_crn == null && var.enable_collecting_failed_events ? "https://${module.cos[0].s3_endpoint_direct}" : null
214+
cos_instance_guid = var.existing_event_notifications_instance_crn == null ? (var.existing_cos_instance_crn == null ? (length(module.cos_buckets) > 0 ? module.cos_buckets.bucket_configs.cos_instance_guid : null) : module.existing_cos_crn_parser[0].service_instance) : null
215+
cos_bucket_endpoint = var.existing_event_notifications_instance_crn == null && var.enable_collecting_failed_events ? module.cos_buckets[0].buckets[local.cos_bucket_name].s3_endpoint_direct : null
213216
cos_account_id = var.existing_event_notifications_instance_crn == null ? var.existing_cos_instance_crn != null ? split("/", module.existing_cos_crn_parser[0].scope)[1] : null : null
214217
}
215218

216-
module "cos" {
217-
count = var.enable_collecting_failed_events && var.existing_event_notifications_instance_crn == null ? 1 : 0
218-
source = "terraform-ibm-modules/cos/ibm"
219-
version = "8.21.8"
220-
create_cos_instance = false
221-
create_cos_bucket = true
222-
kms_encryption_enabled = var.kms_encryption_enabled_bucket
223-
bucket_storage_class = var.cos_bucket_class
224-
existing_cos_instance_id = var.existing_cos_instance_crn
225-
skip_iam_authorization_policy = local.create_cross_account_en_kms_auth_policy || local.create_cross_account_cos_kms_auth_policy || var.skip_cos_kms_auth_policy
226-
add_bucket_name_suffix = var.add_bucket_name_suffix
227-
region = local.cos_bucket_region
228-
bucket_name = local.cos_bucket_name
229-
access_tags = var.cos_bucket_access_tags
230-
management_endpoint_type_for_bucket = var.management_endpoint_type_for_bucket
231-
existing_kms_instance_guid = local.existing_kms_guid
232-
kms_key_crn = local.cos_kms_key_crn
219+
locals {
220+
bucket_config = [{
221+
access_tags = var.cos_bucket_access_tags
222+
bucket_name = local.cos_bucket_name
223+
add_bucket_name_suffix = var.add_bucket_name_suffix
224+
kms_encryption_enabled = var.kms_encryption_enabled_bucket
225+
kms_guid = local.existing_kms_guid
226+
kms_key_crn = local.cos_kms_key_crn
227+
skip_iam_authorization_policy = var.skip_cos_kms_auth_policy
228+
management_endpoint_type = var.management_endpoint_type_for_bucket
229+
storage_class = var.cos_bucket_class
230+
resource_instance_id = var.existing_cos_instance_crn
231+
region_location = local.cos_bucket_region
232+
force_delete = true
233+
}]
234+
}
235+
236+
module "cos_buckets" {
237+
count = var.enable_collecting_failed_events && var.existing_event_notifications_instance_crn == null ? 1 : 0
238+
source = "terraform-ibm-modules/cos/ibm//modules/buckets"
239+
version = "8.19.2"
240+
bucket_configs = local.bucket_config
233241
}
234242

235243
########################################################################################################################
@@ -282,7 +290,7 @@ module "event_notifications" {
282290
cos_integration_enabled = var.enable_collecting_failed_events
283291
cos_bucket_name = local.cos_bucket_name_with_suffix
284292
cos_instance_id = var.existing_cos_instance_crn
285-
skip_en_cos_auth_policy = var.skip_event_notifications_cos_auth_policy || local.create_cross_account_cos_kms_auth_policy
293+
skip_en_cos_auth_policy = var.skip_event_notifications_cos_auth_policy
286294
cos_endpoint = "https://${local.cos_bucket_endpoint}"
287295
cbr_rules = var.cbr_rules
288296
}

solutions/fully-configurable/variables.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ variable "kms_encryption_enabled" {
119119
description = "Set to true to enable KMS encryption on Event Notifications instance and Cloud Object Storage bucket. When set to true 'kms_endpoint_url' and one of 'existing_kms_instance_crn' or 'existing_kms_root_key_crn' must be set."
120120
default = true
121121
validation {
122-
condition = var.kms_encryption_enabled == true ? (var.existing_kms_instance_crn != null && var.existing_kms_root_key_crn == null) || (var.existing_kms_instance_crn == null && var.existing_kms_root_key_crn != null) : true
123-
error_message = "You must provide one of 'existing_kms_instance_crn' or 'existing_kms_root_key_crn' if 'kms_encryption_enabled' is set to true."
122+
condition = var.kms_encryption_enabled == true ? (var.existing_kms_instance_crn != null || var.existing_kms_root_key_crn != null) : true
123+
error_message = "You must provide at least one of 'existing_kms_instance_crn' or 'existing_kms_root_key_crn' if 'kms_encryption_enabled' is set to true."
124124
}
125125
}
126126

tests/pr_test.go

+33-7
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,12 @@ func TestRunExistingResourcesInstances(t *testing.T) {
345345

346346
options := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{
347347
Testing: t,
348-
Prefix: "en-ex-res",
348+
Prefix: "enexres",
349349
TarIncludePatterns: []string{
350350
"*.tf",
351351
fullyConfigurableDADir + "/*.tf",
352-
secEnforcedDir + "/*.tf",
353352
},
354-
TemplateFolder: secEnforcedDir,
353+
TemplateFolder: fullyConfigurableDADir,
355354
Tags: []string{"test-schematic"},
356355
DeleteWorkspaceOnFail: false,
357356
WaitJobCompleteMinutes: 60,
@@ -375,13 +374,12 @@ func TestRunExistingResourcesInstances(t *testing.T) {
375374

376375
options2 := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{
377376
Testing: t,
378-
Prefix: "en-ex-res2",
377+
Prefix: "enexres2",
379378
TarIncludePatterns: []string{
380379
"*.tf",
381380
fullyConfigurableDADir + "/*.tf",
382-
secEnforcedDir + "/*.tf",
383381
},
384-
TemplateFolder: secEnforcedDir,
382+
TemplateFolder: fullyConfigurableDADir,
385383
Tags: []string{"test-schematic"},
386384
DeleteWorkspaceOnFail: false,
387385
WaitJobCompleteMinutes: 60,
@@ -395,11 +393,39 @@ func TestRunExistingResourcesInstances(t *testing.T) {
395393
{Name: "existing_kms_root_key_crn", Value: terraform.Output(t, existingTerraformOptions, "key_crn"), DataType: "string"},
396394
{Name: "kms_endpoint_url", Value: permanentResources["hpcs_south_private_endpoint"], DataType: "string"},
397395
{Name: "existing_cos_instance_crn", Value: terraform.Output(t, existingTerraformOptions, "cos_crn"), DataType: "string"},
396+
{Name: "kms_encryption_enabled_bucket", Value: false, DataType: "bool"},
398397
}
399398
err2 := options2.RunSchematicTest()
400399
assert.NoError(t, err2, "TestRunExistingResourcesInstances using existing RG, COS instance, and KMS key Failed")
401-
}
402400

401+
// ------------------------------------------------------------------------------------
402+
// Deploy EN DA passing in existing RG, COS instance and KMS instance
403+
// ------------------------------------------------------------------------------------
404+
options3 := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{
405+
Testing: t,
406+
Prefix: "enexsres3",
407+
TarIncludePatterns: []string{
408+
"*.tf",
409+
fullyConfigurableDADir + "/*.tf",
410+
},
411+
TemplateFolder: fullyConfigurableDADir,
412+
Tags: []string{"test-schematic"},
413+
DeleteWorkspaceOnFail: false,
414+
WaitJobCompleteMinutes: 60,
415+
})
416+
options3.TerraformVars = []testschematic.TestSchematicTerraformVar{
417+
{Name: "prefix", Value: options3.Prefix, DataType: "string"},
418+
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
419+
{Name: "region", Value: region, DataType: "string"},
420+
{Name: "existing_resource_group_name", Value: permanentResources["general_test_storage_cos_instance_resource_group"], DataType: "string"},
421+
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
422+
{Name: "kms_endpoint_url", Value: permanentResources["hpcs_south_private_endpoint"], DataType: "string"},
423+
{Name: "existing_cos_instance_crn", Value: terraform.Output(t, existingTerraformOptions, "cos_crn"), DataType: "string"},
424+
{Name: "cos_bucket_name", Value: terraform.Output(t, existingTerraformOptions, "bucket_name"), DataType: "string"},
425+
}
426+
err3 := options3.RunSchematicTest()
427+
assert.NoError(t, err3, "TestRunExistingResourcesInstances using existing RG, COS instance and KMS instance Failed")
428+
}
403429
// Check if "DO_NOT_DESTROY_ON_FAILURE" is set
404430
envVal, _ := os.LookupEnv("DO_NOT_DESTROY_ON_FAILURE")
405431
// Destroy the temporary existing resources if required

0 commit comments

Comments
 (0)