Skip to content

Commit bf07db0

Browse files
authored
fix: skip call to cos module when providing existing bucket in the DA solution (#220)
1 parent 8e294b0 commit bf07db0

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

solutions/standard/main.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,15 @@ locals {
7979
# tflint-ignore: terraform_unused_declarations
8080
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
8181
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
82-
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
82+
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
8383
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)
84-
cos_bucket_name_with_suffix = var.existing_cos_bucket_name != null ? var.existing_cos_bucket_name : module.cos.bucket_name
84+
cos_bucket_name_with_suffix = var.existing_cos_bucket_name != null ? var.existing_cos_bucket_name : module.cos[0].bucket_name
8585
cos_bucket_region = var.cos_bucket_region != null ? var.cos_bucket_region : var.cross_region_location != null ? null : var.region
8686
cos_instance_name = var.prefix != null ? "${var.prefix}-${var.cos_instance_name}" : var.cos_instance_name
8787
}
8888

8989
module "cos" {
90+
count = var.existing_cos_bucket_name != null ? 0 : 1
9091
source = "terraform-ibm-modules/cos/ibm"
9192
version = "8.4.1"
9293
create_cos_instance = var.existing_cos_instance_crn == null ? true : false
@@ -119,7 +120,7 @@ module "cos" {
119120
locals {
120121
# KMS Related
121122
existing_kms_instance_crn = var.existing_kms_instance_crn != null ? var.existing_kms_instance_crn : null
122-
cos_endpoint = var.existing_cos_bucket_name == null ? "https://${module.cos.s3_endpoint_public}" : var.existing_cos_endpoint
123+
cos_endpoint = var.existing_cos_bucket_name == null ? "https://${module.cos[0].s3_endpoint_public}" : var.existing_cos_endpoint
123124
}
124125

125126
module "event_notifications" {

solutions/standard/moved.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
moved {
2+
from = module.cos
3+
to = module.cos[0]
4+
}

tests/pr_test.go

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
const completeExampleDir = "examples/complete"
1717
const fsExampleDir = "examples/fscloud"
18-
const daDir = "solutions/standard"
18+
const solutionDADir = "solutions/standard"
1919

2020
// Use existing group for tests
2121
const resourceGroup = "geretain-test-event-notifications"
@@ -82,18 +82,6 @@ func TestRunCompleteExample(t *testing.T) {
8282
assert.NotNil(t, output, "Expected some output")
8383
}
8484

85-
func TestRunUpgradeExample(t *testing.T) {
86-
t.Parallel()
87-
88-
options := setupOptions(t, "event-notification-upg", completeExampleDir)
89-
90-
output, err := options.RunTestUpgrade()
91-
if !options.UpgradeTestSkipped {
92-
assert.Nil(t, err, "This should not have errored")
93-
assert.NotNil(t, output, "Expected some output")
94-
}
95-
}
96-
9785
func TestRunFSCloudExample(t *testing.T) {
9886
t.Parallel()
9987

@@ -111,13 +99,13 @@ func TestDAInSchematics(t *testing.T) {
11199

112100
options := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{
113101
Testing: t,
114-
Prefix: "scc-da",
102+
Prefix: "en-da",
115103
TarIncludePatterns: []string{
116104
"*.tf",
117-
daDir + "/*.tf",
105+
solutionDADir + "/*.tf",
118106
},
119107
ResourceGroup: resourceGroup,
120-
TemplateFolder: daDir,
108+
TemplateFolder: solutionDADir,
121109
Tags: []string{"test-schematic"},
122110
DeleteWorkspaceOnFail: false,
123111
WaitJobCompleteMinutes: 60,
@@ -135,3 +123,32 @@ func TestDAInSchematics(t *testing.T) {
135123
err := options.RunSchematicTest()
136124
assert.Nil(t, err, "This should not have errored")
137125
}
126+
127+
func TestRunUpgradeDASolution(t *testing.T) {
128+
t.Parallel()
129+
130+
var region = validRegions[rand.Intn(len(validRegions))]
131+
132+
options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
133+
Testing: t,
134+
TerraformDir: solutionDADir,
135+
Prefix: "en-da-upg",
136+
})
137+
138+
terraformVars := map[string]interface{}{
139+
"ibmcloud_api_key": options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"],
140+
"resource_group_name": options.Prefix,
141+
"region": region,
142+
"existing_kms_instance_crn": permanentResources["hpcs_south_crn"],
143+
"existing_kms_root_key_crn": permanentResources["hpcs_south_root_key_crn"],
144+
"kms_endpoint_url": permanentResources["hpcs_south_private_endpoint"],
145+
"management_endpoint_type_for_bucket": "public",
146+
}
147+
148+
options.TerraformVars = terraformVars
149+
output, err := options.RunTestUpgrade()
150+
if !options.UpgradeTestSkipped {
151+
assert.Nil(t, err, "This should not have errored")
152+
assert.NotNil(t, output, "Expected some output")
153+
}
154+
}

0 commit comments

Comments
 (0)