Skip to content

Commit

Permalink
fix: skip call to cos module when providing existing bucket in the DA…
Browse files Browse the repository at this point in the history
… solution (#220)
  • Loading branch information
shemau authored Jun 18, 2024
1 parent 8e294b0 commit bf07db0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
7 changes: 4 additions & 3 deletions solutions/standard/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" {
Expand Down
4 changes: 4 additions & 0 deletions solutions/standard/moved.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
moved {
from = module.cos
to = module.cos[0]
}
49 changes: 33 additions & 16 deletions tests/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()

Expand All @@ -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,
Expand All @@ -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")
}
}

0 comments on commit bf07db0

Please sign in to comment.