You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Validation (approach based on https://github.com/hashicorp/terraform/issues/25609#issuecomment-1057614400)
7
-
# tflint-ignore: terraform_unused_declarations
8
-
validate_kms_values=var.use_ibm_owned_encryption_key&& (var.kms_key_crn!=null|| var.backup_encryption_key_crn!=null) ?tobool("When passing values for 'kms_key_crn' or 'backup_encryption_key_crn', you must set 'use_ibm_owned_encryption_key' to false. Otherwise unset them to use default encryption.") :true
9
-
# tflint-ignore: terraform_unused_declarations
10
-
validate_kms_vars=!var.use_ibm_owned_encryption_key&& var.kms_key_crn==null?tobool("When setting 'use_ibm_owned_encryption_key' to false, a value must be passed for 'kms_key_crn'.") :true
11
-
# tflint-ignore: terraform_unused_declarations
12
-
validate_backup_key=!var.use_ibm_owned_encryption_key&& var.backup_encryption_key_crn!=null&& (var.use_default_backup_encryption_key|| var.use_same_kms_key_for_backups) ?tobool("When passing a value for 'backup_encryption_key_crn' you cannot set 'use_default_backup_encryption_key' to true or 'use_ibm_owned_encryption_key' to false.") :true
13
-
# tflint-ignore: terraform_unused_declarations
14
-
validate_backup_key_2=!var.use_ibm_owned_encryption_key&& var.backup_encryption_key_crn==null&&!var.use_same_kms_key_for_backups?tobool("When 'use_same_kms_key_for_backups' is set to false, a value needs to be passed for 'backup_encryption_key_crn'.") :true
validate_kms_1=var.existing_mongodb_instance_crn!=null?true: var.use_ibm_owned_encryption_key&& (var.existing_kms_instance_crn!=null|| var.existing_kms_key_crn!=null|| var.existing_backup_kms_key_crn!=null) ?tobool("When setting values for 'existing_kms_instance_crn', 'existing_kms_key_crn' or 'existing_backup_kms_key_crn', the 'use_ibm_owned_encryption_key' input must be set to false.") :true
22
-
# tflint-ignore: terraform_unused_declarations
23
-
validate_kms_2=var.existing_mongodb_instance_crn!=null?true:!var.use_ibm_owned_encryption_key&& (var.existing_kms_instance_crn==null&& var.existing_kms_key_crn==null) ?tobool("When 'use_ibm_owned_encryption_key' is false, a value is required for either 'existing_kms_instance_crn' (to create a new key), or 'existing_kms_key_crn' to use an existing key.") :true
# Validate the region input matches region detected in existing instance CRN (approach based on https://github.com/hashicorp/terraform/issues/25609#issuecomment-1057614400)
264
-
# tflint-ignore: terraform_unused_declarations
265
-
validate_existing_instance_region=var.existing_mongodb_instance_crn!=null&& var.region!= local.existing_mongodb_region?tobool("The region detected in the 'existing_mongodb_instance_crn' value must match the value of the 'region' input variable when passing an existing instance.") :true
266
248
}
267
249
268
250
# Do a data lookup on the resource GUID to get more info that is needed for the 'ibm_database' data lookup below
## Variable validation (approach based on https://github.com/hashicorp/terraform/issues/25609#issuecomment-1057614400)
337
-
# tflint-ignore: terraform_unused_declarations
338
-
validate_secret_manager_crn=length(local.service_credential_secrets) >0&& var.existing_secrets_manager_instance_crn==null?tobool("`existing_secrets_manager_instance_crn` is required when adding service credentials to a secrets manager secret.") :false
339
-
# tflint-ignore: terraform_unused_declarations
340
-
validate_secret_manager_sg=var.existing_secrets_manager_instance_crn!=null&& var.admin_pass_secret_manager_secret_group==null?tobool("`admin_pass_secret_manager_secret_group` is required when `existing_secrets_manager_instance_crn` is set.") :false
341
-
# tflint-ignore: terraform_unused_declarations
342
-
validate_secret_manager_sn=var.existing_secrets_manager_instance_crn!=null&& var.admin_pass_secret_manager_secret_name==null?tobool("`admin_pass_secret_manager_secret_name` is required when `existing_secrets_manager_instance_crn` is set.") :false
error_message="The region detected in the 'existing_mongodb_instance_crn' value must match the value of the 'region' input variable when passing an existing instance."
description="IBM Cloud Databases will secure your deployment's data at rest automatically with an encryption key that IBM hold. Alternatively, you may select your own Key Management System instance and encryption key (Key Protect or Hyper Protect Crypto Services) by setting this to false. If setting to false, a value must be passed for `existing_kms_instance_crn` to create a new key, or `existing_kms_key_crn` and/or `existing_backup_kms_key_crn` to use an existing key."
148
153
default=false
154
+
155
+
validation {
156
+
condition=(
157
+
var.existing_mongodb_instance_crn!=null||
158
+
!(var.use_ibm_owned_encryption_key&& (
159
+
var.existing_kms_instance_crn!=null||
160
+
var.existing_kms_key_crn!=null||
161
+
var.existing_backup_kms_key_crn!=null
162
+
))
163
+
)
164
+
error_message="When setting values for 'existing_kms_instance_crn', 'existing_kms_key_crn' or 'existing_backup_kms_key_crn', the 'use_ibm_owned_encryption_key' input must be set to false."
165
+
}
166
+
167
+
# this validation ensures key info is provided when IBM-owned key is disabled and no MongoDB instance is given
168
+
validation {
169
+
condition=!(
170
+
var.existing_mongodb_instance_crn==null&&
171
+
var.use_ibm_owned_encryption_key==false&&
172
+
var.existing_kms_instance_crn==null&&
173
+
var.existing_kms_key_crn==null
174
+
)
175
+
error_message="When 'use_ibm_owned_encryption_key' is false, you must provide either 'existing_kms_instance_crn' (to create a new key) or 'existing_kms_key_crn' (to use an existing key)."
description="The name of a new or existing secrets manager secret group for admin password. To use existing secret group, `use_existing_admin_pass_secrets_manager_secret_group` must be set to `true`. If a prefix input variable is specified, the prefix is added to the name in the `<prefix>-<name>` format."
326
362
default="mongodb-secrets"
363
+
364
+
validation {
365
+
condition=(
366
+
var.existing_secrets_manager_instance_crn==null||
367
+
var.admin_pass_secret_manager_secret_group!=null
368
+
)
369
+
error_message="`admin_pass_secret_manager_secret_group` is required when `existing_secrets_manager_instance_crn` is set."
description="The name of a new mongodb administrator secret. If a prefix input variable is specified, the prefix is added to the name in the `<prefix>-<name>` format."
338
382
default="mongodb-admin-password"
383
+
validation {
384
+
condition=(
385
+
var.existing_secrets_manager_instance_crn==null||
386
+
var.admin_pass_secret_manager_secret_name!=null
387
+
)
388
+
error_message="`admin_pass_secret_manager_secret_name` is required when `existing_secrets_manager_instance_crn` is set."
description="IBM Cloud Databases will secure your deployment's data at rest automatically with an encryption key that IBM hold. Alternatively, you may select your own Key Management System instance and encryption key (Key Protect or Hyper Protect Crypto Services) by setting this to false. If setting to false, a value must be passed for the `kms_key_crn` input."
error_message="When passing a value for 'backup_encryption_key_crn' you cannot set 'use_default_backup_encryption_key' to true or 'use_ibm_owned_encryption_key' to false."
210
+
}
211
+
212
+
validation {
213
+
condition=(
214
+
var.use_ibm_owned_encryption_key||
215
+
var.backup_encryption_key_crn!=null||
216
+
var.use_same_kms_key_for_backups
217
+
)
218
+
error_message="When 'use_same_kms_key_for_backups' is set to false, a value needs to be passed for 'backup_encryption_key_crn'."
0 commit comments