Skip to content

Commit 7d84e1d

Browse files
committed
SKIP UPGRADE TEST fix unit test and variable validation
1 parent df45394 commit 7d84e1d

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

solutions/fully-configurable/variables.tf

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,19 @@ variable "kms_encryption_enabled" {
169169
description = "Set to true to enable KMS Encryption using customer managed keys. When set to true, a value must be passed for either 'existing_kms_instance_crn', 'existing_kms_key_crn' or 'existing_backup_kms_key_crn'."
170170
default = false
171171

172-
# this validation ensures key info is provided when Kms encryption is enabled and no MongoDB instance is given
173172
validation {
174-
condition = (
175-
var.existing_mongodb_instance_crn != null ||
176-
(var.kms_encryption_enabled && (
177-
var.existing_kms_instance_crn != null ||
178-
var.existing_kms_key_crn != null ||
179-
var.existing_backup_kms_key_crn != null
180-
))
181-
)
182-
error_message = "When setting values for 'existing_kms_instance_crn', 'existing_kms_key_crn' or 'existing_backup_kms_key_crn', the 'kms_encryption_enabled' input must be set to true."
173+
condition = var.existing_mongodb_instance_crn != null ? var.kms_encryption_enabled == false : true
174+
error_message = "When using an existing mongodb instance 'kms_encryption_enabled' should not be enabled"
175+
}
176+
177+
validation {
178+
condition = var.kms_encryption_enabled == true ? (var.existing_kms_instance_crn != null || var.existing_kms_key_crn != null || var.existing_backup_kms_key_crn != null) : true
179+
error_message = "You must provide at least one of 'existing_kms_instance_crn', 'existing_kms_root_key_crn' or 'existing_backup_kms_key_crn' inputs if 'kms_encryption_enabled' is set to true."
180+
}
181+
182+
validation {
183+
condition = var.kms_encryption_enabled == false ? (var.existing_kms_key_crn == null && var.existing_kms_instance_crn == null && var.existing_backup_kms_key_crn == null) : true
184+
error_message = "If 'kms_encryption_enabled' is set to false, you should not pass values for 'existing_kms_instance_crn', 'existing_kms_root_key_crn' or 'existing_backup_kms_key_crn'. inputs"
183185
}
184186
}
185187

tests/pr_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func TestRunFullyConfigurableUpgradeSolution(t *testing.T) {
128128
})
129129

130130
options.TerraformVars = map[string]interface{}{
131+
"prefix": options.Prefix,
131132
"mongodb_access_tags": permanentResources["accessTags"],
132133
"kms_encryption_enabled": true,
133134
"use_ibm_owned_encryption_key": false,
@@ -252,6 +253,7 @@ func TestRunExistingInstance(t *testing.T) {
252253
})
253254

254255
options.TerraformVars = []testschematic.TestSchematicTerraformVar{
256+
{Name: "prefix", Value: options.Prefix, DataType: "string"},
255257
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
256258
{Name: "existing_mongodb_instance_crn", Value: terraform.Output(t, existingTerraformOptions, "mongodb_crn"), DataType: "string"},
257259
{Name: "existing_resource_group_name", Value: resourceGroup, DataType: "string"},
@@ -283,7 +285,7 @@ func TestRunfullyConfigurableSolutionIBMKeys(t *testing.T) {
283285
Testing: t,
284286
TerraformDir: fullyConfigurableSolutionTerraformDir,
285287
Region: "us-south",
286-
Prefix: "mongodb-icd-key",
288+
Prefix: "mongo-key",
287289
ResourceGroup: resourceGroup,
288290
})
289291

0 commit comments

Comments
 (0)