diff --git a/solutions/standard/main.tf b/solutions/standard/main.tf index 3b22e03b..03bac7a5 100644 --- a/solutions/standard/main.tf +++ b/solutions/standard/main.tf @@ -79,14 +79,15 @@ locals { # tflint-ignore: terraform_unused_declarations validate_cos_regions = var.cos_bucket_region != null && var.cross_region_location != null ? tobool("Cannot provide values for var.cos_bucket_region and var.cross_region_location") : true cos_kms_key_crn = var.existing_cos_bucket_name != null ? null : var.existing_kms_root_key_crn != null ? var.existing_kms_root_key_crn : module.kms[0].keys[format("%s.%s", var.cos_key_ring_name, var.cos_key_name)].crn - cos_instance_guid = var.existing_cos_instance_crn != null ? element(split(":", var.existing_cos_instance_crn), length(split(":", var.existing_cos_instance_crn)) - 3) : module.cos.cos_instance_guid + cos_instance_guid = var.existing_cos_instance_crn != null ? element(split(":", var.existing_cos_instance_crn), length(split(":", var.existing_cos_instance_crn)) - 3) : module.cos[0].cos_instance_guid cos_bucket_name = var.existing_cos_bucket_name != null ? var.existing_cos_bucket_name : (var.prefix != null ? "${var.prefix}-${var.cos_bucket_name}" : var.cos_bucket_name) - cos_bucket_name_with_suffix = var.existing_cos_bucket_name != null ? var.existing_cos_bucket_name : module.cos.bucket_name + cos_bucket_name_with_suffix = var.existing_cos_bucket_name != null ? var.existing_cos_bucket_name : module.cos[0].bucket_name cos_bucket_region = var.cos_bucket_region != null ? var.cos_bucket_region : var.cross_region_location != null ? null : var.region cos_instance_name = var.prefix != null ? "${var.prefix}-${var.cos_instance_name}" : var.cos_instance_name } module "cos" { + count = var.existing_cos_bucket_name != null ? 0 : 1 source = "terraform-ibm-modules/cos/ibm" version = "8.4.1" create_cos_instance = var.existing_cos_instance_crn == null ? true : false @@ -119,7 +120,7 @@ module "cos" { locals { # KMS Related existing_kms_instance_crn = var.existing_kms_instance_crn != null ? var.existing_kms_instance_crn : null - cos_endpoint = var.existing_cos_bucket_name == null ? "https://${module.cos.s3_endpoint_public}" : var.existing_cos_endpoint + cos_endpoint = var.existing_cos_bucket_name == null ? "https://${module.cos[0].s3_endpoint_public}" : var.existing_cos_endpoint } module "event_notifications" { diff --git a/solutions/standard/moved.tf b/solutions/standard/moved.tf new file mode 100644 index 00000000..1ce361e3 --- /dev/null +++ b/solutions/standard/moved.tf @@ -0,0 +1,4 @@ +moved { + from = module.cos + to = module.cos[0] +} diff --git a/tests/pr_test.go b/tests/pr_test.go index 5e9008dc..f634caf9 100644 --- a/tests/pr_test.go +++ b/tests/pr_test.go @@ -15,7 +15,7 @@ import ( const completeExampleDir = "examples/complete" const fsExampleDir = "examples/fscloud" -const daDir = "solutions/standard" +const solutionDADir = "solutions/standard" // Use existing group for tests const resourceGroup = "geretain-test-event-notifications" @@ -82,18 +82,6 @@ func TestRunCompleteExample(t *testing.T) { assert.NotNil(t, output, "Expected some output") } -func TestRunUpgradeExample(t *testing.T) { - t.Parallel() - - options := setupOptions(t, "event-notification-upg", completeExampleDir) - - output, err := options.RunTestUpgrade() - if !options.UpgradeTestSkipped { - assert.Nil(t, err, "This should not have errored") - assert.NotNil(t, output, "Expected some output") - } -} - func TestRunFSCloudExample(t *testing.T) { t.Parallel() @@ -111,13 +99,13 @@ func TestDAInSchematics(t *testing.T) { options := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{ Testing: t, - Prefix: "scc-da", + Prefix: "en-da", TarIncludePatterns: []string{ "*.tf", - daDir + "/*.tf", + solutionDADir + "/*.tf", }, ResourceGroup: resourceGroup, - TemplateFolder: daDir, + TemplateFolder: solutionDADir, Tags: []string{"test-schematic"}, DeleteWorkspaceOnFail: false, WaitJobCompleteMinutes: 60, @@ -135,3 +123,32 @@ func TestDAInSchematics(t *testing.T) { err := options.RunSchematicTest() assert.Nil(t, err, "This should not have errored") } + +func TestRunUpgradeDASolution(t *testing.T) { + t.Parallel() + + var region = validRegions[rand.Intn(len(validRegions))] + + options := testhelper.TestOptionsDefault(&testhelper.TestOptions{ + Testing: t, + TerraformDir: solutionDADir, + Prefix: "en-da-upg", + }) + + terraformVars := map[string]interface{}{ + "ibmcloud_api_key": options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], + "resource_group_name": options.Prefix, + "region": region, + "existing_kms_instance_crn": permanentResources["hpcs_south_crn"], + "existing_kms_root_key_crn": permanentResources["hpcs_south_root_key_crn"], + "kms_endpoint_url": permanentResources["hpcs_south_private_endpoint"], + "management_endpoint_type_for_bucket": "public", + } + + options.TerraformVars = terraformVars + output, err := options.RunTestUpgrade() + if !options.UpgradeTestSkipped { + assert.Nil(t, err, "This should not have errored") + assert.NotNil(t, output, "Expected some output") + } +}