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
15
-
16
-
# If no value passed for 'backup_encryption_key_crn' use the value of 'kms_key_crn' and perform validation of 'kms_key_crn' to check if region is supported by backup encryption key.
17
-
18
6
# If 'use_ibm_owned_encryption_key' is true or 'use_default_backup_encryption_key' is true, default to null.
19
7
# If no value is passed for 'backup_encryption_key_crn', then default to use 'kms_key_crn'.
validate_kms_1=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.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)
259
-
# tflint-ignore: terraform_unused_declarations
260
-
validate_existing_instance_region=var.existing_mysql_instance_crn!=null&& var.region!= local.existing_mysql_region?tobool("The region detected in the 'existing_mysql_instance_crn' value must match the value of the 'region' input variable when passing an existing instance.") :true
261
243
}
262
244
263
245
# Do a data lookup on the resource GUID to get more info that is needed for the 'ibm_database' data lookup below
@@ -332,13 +314,6 @@ locals {
332
314
333
315
locals {
334
316
## Variable validation (approach based on https://github.com/hashicorp/terraform/issues/25609#issuecomment-1057614400)
335
-
# tflint-ignore: terraform_unused_declarations
336
-
validate_sm_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
337
-
# tflint-ignore: terraform_unused_declarations
338
-
validate_sm_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
339
-
# tflint-ignore: terraform_unused_declarations
340
-
validate_sm_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_mysql_instance_crn' value must match the value of the 'region' input variable when passing an existing instance."
40
+
}
37
41
}
38
42
39
43
variable"existing_mysql_instance_crn" {
40
44
type=string
41
45
default=null
42
46
description="The CRN of an existing Databases for MySql instance. If no value is specified, a new instance is created."
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."
175
180
default=false
181
+
validation {
182
+
condition=(
183
+
var.existing_mysql_instance_crn!=null||
184
+
!(var.use_ibm_owned_encryption_key&& (
185
+
var.existing_kms_instance_crn!=null||
186
+
var.existing_kms_key_crn!=null||
187
+
var.existing_backup_kms_key_crn!=null
188
+
))
189
+
)
190
+
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."
191
+
}
192
+
193
+
# this validation ensures key info is provided when IBM-owned key is disabled and no Redis instance is given
194
+
validation {
195
+
condition=!(
196
+
var.existing_mysql_instance_crn==null&&
197
+
var.use_ibm_owned_encryption_key==false&&
198
+
var.existing_kms_instance_crn==null&&
199
+
var.existing_kms_key_crn==null
200
+
)
201
+
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_secret_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."
353
388
default="mysql-secrets"
389
+
390
+
validation {
391
+
condition=(
392
+
var.existing_secrets_manager_instance_crn==null||
393
+
var.admin_pass_secret_manager_secret_group!=null
394
+
)
395
+
error_message="`admin_pass_secret_manager_secret_group` is required when `existing_secrets_manager_instance_crn` is set."
description="Whether to use an existing secrets manager secret group for admin password."
359
402
default=false
403
+
360
404
}
361
405
362
406
variable"admin_pass_secret_manager_secret_name" {
363
407
type=string
364
408
description="The name of a new redis administrator secret. If a prefix input variable is specified, the prefix is added to the name in the `<prefix>-<name>` format."
365
409
default="mysql-admin-password"
410
+
411
+
validation {
412
+
condition=(
413
+
var.existing_secrets_manager_instance_crn==null||
414
+
var.admin_pass_secret_manager_secret_name!=null
415
+
)
416
+
error_message="`admin_pass_secret_manager_secret_name` is required when `existing_secrets_manager_instance_crn` is set."
0 commit comments