Skip to content

Commit ae87721

Browse files
authored
fix: fix bug when using existing COS but creating new KMS key (#334)
1 parent 0c24648 commit ae87721

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ locals {
118118

119119
# fetch KMS region from cos_kms_key_crn
120120
kms_region = var.enable_cos_kms_encryption && var.cos_kms_key_crn != null ? module.cos_kms_key_crn_parser[0].region : null
121-
cos_kms_new_key_name = var.existing_cos_instance_crn == null ? "${local.prefix}${var.cos_kms_new_key_name}" : null
121+
cos_kms_new_key_name = var.enable_cos_kms_encryption && var.cos_kms_key_crn == null ? "${local.prefix}${var.cos_kms_new_key_name}" : null
122122
}
123123

124124
module "cos" {

tests/pr_test.go

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func TestRunUpgradeRootDA(t *testing.T) {
144144
}
145145
}
146146

147-
func TestWithExistingKP(t *testing.T) {
147+
func TestWithExistingKPKey(t *testing.T) {
148148
t.Parallel()
149149

150150
region := validRegions[rand.Intn(len(validRegions))]
@@ -188,11 +188,54 @@ func TestWithExistingKP(t *testing.T) {
188188
cleanupResources(t, existingTerraformOptions, prefix)
189189
}
190190

191-
func TestRunUpgradeExistingKP(t *testing.T) {
191+
func TestWithExistingKP(t *testing.T) {
192+
t.Parallel()
193+
194+
region := validRegions[rand.Intn(len(validRegions))]
195+
prefix := fmt.Sprintf("kp-wx-%s", strings.ToLower(random.UniqueId()))
196+
197+
// Provision Existing KMS instance
198+
existingTerraformOptions := setupKMSKeyProtect(t, region, prefix)
199+
200+
// Deploy watsonx DA using existing KP details
201+
options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
202+
Testing: t,
203+
TerraformDir: rootDaDir,
204+
IgnoreDestroys: testhelper.Exemptions{ // Ignore for consistency check
205+
List: []string{
206+
"module.configure_user.null_resource.configure_user",
207+
"module.configure_user.null_resource.restrict_access",
208+
},
209+
},
210+
IgnoreUpdates: testhelper.Exemptions{ // Ignore for consistency check
211+
List: []string{
212+
"module.configure_user.null_resource.configure_user",
213+
"module.configure_user.null_resource.restrict_access",
214+
},
215+
},
216+
})
217+
218+
options.TerraformVars = map[string]interface{}{
219+
"region": region,
220+
"provider_visibility": "public",
221+
"enable_cos_kms_encryption": true,
222+
"cos_kms_crn": terraform.Output(t, existingTerraformOptions, "key_protect_crn"),
223+
"existing_cos_instance_crn": terraform.Output(t, existingTerraformOptions, "cos_crn"),
224+
"prefix": prefix,
225+
}
226+
227+
output, err := options.RunTestConsistency()
228+
assert.Nil(t, err, "This should not have errored")
229+
assert.NotNil(t, output, "Expected some output")
230+
231+
cleanupResources(t, existingTerraformOptions, prefix)
232+
}
233+
234+
func TestRunUpgradeExistingKPNewKey(t *testing.T) {
192235
t.Parallel()
193236

194237
region := validRegions[rand.Intn(len(validRegions))]
195-
prefix := fmt.Sprintf("kp-ut-%s", strings.ToLower(random.UniqueId()))
238+
prefix := fmt.Sprintf("kp-t-%s", strings.ToLower(random.UniqueId()))
196239

197240
// Provision Existing KMS instance
198241
existingTerraformOptions := setupKMSKeyProtect(t, region, prefix)

0 commit comments

Comments
 (0)