diff --git a/README.md b/README.md
index 80f95b80..2e473d28 100644
--- a/README.md
+++ b/README.md
@@ -55,7 +55,7 @@ You need the following permissions to run this module.
| Name | Version |
|------|---------|
-| [terraform](#requirement\_terraform) | >= 1.3.0 |
+| [terraform](#requirement\_terraform) | >= 1.9.0 |
| [ibm](#requirement\_ibm) | >= 1.70.0, < 2.0.0 |
| [time](#requirement\_time) | >= 0.9.1, < 1.0.0 |
diff --git a/examples/backup-restore/version.tf b/examples/backup-restore/version.tf
index 05dee1cd..be412f48 100644
--- a/examples/backup-restore/version.tf
+++ b/examples/backup-restore/version.tf
@@ -1,5 +1,5 @@
terraform {
- required_version = ">= 1.3.0"
+ required_version = ">= 1.9.0"
required_providers {
# Use latest version of provider in non-basic examples to verify latest version works with module
ibm = {
diff --git a/examples/basic/version.tf b/examples/basic/version.tf
index d4e885b2..c4df18ba 100644
--- a/examples/basic/version.tf
+++ b/examples/basic/version.tf
@@ -1,5 +1,5 @@
terraform {
- required_version = ">= 1.3.0"
+ required_version = ">= 1.9.0"
required_providers {
# Use latest version of provider in non-basic examples to verify latest version works with module
ibm = {
diff --git a/examples/complete/version.tf b/examples/complete/version.tf
index 05dee1cd..be412f48 100644
--- a/examples/complete/version.tf
+++ b/examples/complete/version.tf
@@ -1,5 +1,5 @@
terraform {
- required_version = ">= 1.3.0"
+ required_version = ">= 1.9.0"
required_providers {
# Use latest version of provider in non-basic examples to verify latest version works with module
ibm = {
diff --git a/examples/fscloud/version.tf b/examples/fscloud/version.tf
index b4448636..7c8afe1e 100644
--- a/examples/fscloud/version.tf
+++ b/examples/fscloud/version.tf
@@ -1,5 +1,5 @@
terraform {
- required_version = ">= 1.3.0"
+ required_version = ">= 1.9.0"
required_providers {
# Use latest version of provider in non-basic examples to verify latest version works with module
ibm = {
diff --git a/main.tf b/main.tf
index fb6083e0..3b370ee9 100644
--- a/main.tf
+++ b/main.tf
@@ -2,17 +2,6 @@
# ICD MongoDB module
##############################################################################
-locals {
- # Validation (approach based on https://github.com/hashicorp/terraform/issues/25609#issuecomment-1057614400)
- # tflint-ignore: terraform_unused_declarations
- 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
- # tflint-ignore: terraform_unused_declarations
- 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
- # tflint-ignore: terraform_unused_declarations
- 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
- # tflint-ignore: terraform_unused_declarations
- 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
-}
########################################################################################################################
# Locals
diff --git a/solutions/standard/main.tf b/solutions/standard/main.tf
index 0cc35cc3..0b4473f9 100644
--- a/solutions/standard/main.tf
+++ b/solutions/standard/main.tf
@@ -9,20 +9,6 @@ module "resource_group" {
existing_resource_group_name = var.use_existing_resource_group == true ? var.resource_group_name : null
}
-#######################################################################################################################
-# KMS related variable validation
-# (approach based on https://github.com/hashicorp/terraform/issues/25609#issuecomment-1057614400)
-#
-# TODO: Replace with terraform cross variable validation: https://github.ibm.com/GoldenEye/issues/issues/10836
-#######################################################################################################################
-
-locals {
- # tflint-ignore: terraform_unused_declarations
- 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
- # tflint-ignore: terraform_unused_declarations
- 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
-}
-
#######################################################################################################################
# KMS encryption key
@@ -259,10 +245,6 @@ module "mongodb_instance_crn_parser" {
locals {
existing_mongodb_guid = var.existing_mongodb_instance_crn != null ? module.mongodb_instance_crn_parser[0].service_instance : null
existing_mongodb_region = var.existing_mongodb_instance_crn != null ? module.mongodb_instance_crn_parser[0].region : null
-
- # Validate the region input matches region detected in existing instance CRN (approach based on https://github.com/hashicorp/terraform/issues/25609#issuecomment-1057614400)
- # tflint-ignore: terraform_unused_declarations
- 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
}
# Do a data lookup on the resource GUID to get more info that is needed for the 'ibm_database' data lookup below
@@ -333,14 +315,6 @@ locals {
#######################################################################################################################
locals {
- ## Variable validation (approach based on https://github.com/hashicorp/terraform/issues/25609#issuecomment-1057614400)
- # tflint-ignore: terraform_unused_declarations
- 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
- # tflint-ignore: terraform_unused_declarations
- 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
- # tflint-ignore: terraform_unused_declarations
- 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
-
create_secret_manager_auth_policy = var.skip_mongodb_secret_manager_auth_policy || var.existing_secrets_manager_instance_crn == null ? 0 : 1
}
diff --git a/solutions/standard/variables.tf b/solutions/standard/variables.tf
index f471d1b2..243aa0df 100644
--- a/solutions/standard/variables.tf
+++ b/solutions/standard/variables.tf
@@ -34,6 +34,11 @@ variable "region" {
description = "The region where you want to deploy your instance."
type = string
default = "us-south"
+
+ validation {
+ condition = var.existing_mongodb_instance_crn != null && var.region != local.existing_mongodb_region ? false : true
+ 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."
+ }
}
variable "mongodb_version" {
@@ -146,6 +151,29 @@ variable "use_ibm_owned_encryption_key" {
type = bool
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."
default = false
+
+ validation {
+ condition = (
+ var.existing_mongodb_instance_crn != null ||
+ !(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
+ ))
+ )
+ 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."
+ }
+
+ # this validation ensures key info is provided when IBM-owned key is disabled and no MongoDB instance is given
+ validation {
+ condition = !(
+ var.existing_mongodb_instance_crn == null &&
+ var.use_ibm_owned_encryption_key == false &&
+ var.existing_kms_instance_crn == null &&
+ var.existing_kms_key_crn == null
+ )
+ 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)."
+ }
}
variable "existing_kms_instance_crn" {
@@ -312,6 +340,14 @@ variable "service_credential_secrets" {
])
error_message = "service_credentials_source_service_role_crn must be a serviceRole CRN. See https://cloud.ibm.com/iam/roles"
}
+
+ validation {
+ condition = (
+ length(var.service_credential_secrets) == 0 ||
+ var.existing_secrets_manager_instance_crn != null
+ )
+ error_message = "`existing_secrets_manager_instance_crn` is required when adding service credentials to a secrets manager secret."
+ }
}
variable "skip_mongodb_secret_manager_auth_policy" {
@@ -324,6 +360,14 @@ variable "admin_pass_secret_manager_secret_group" {
type = string
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 `-` format."
default = "mongodb-secrets"
+
+ validation {
+ condition = (
+ var.existing_secrets_manager_instance_crn == null ||
+ var.admin_pass_secret_manager_secret_group != null
+ )
+ error_message = "`admin_pass_secret_manager_secret_group` is required when `existing_secrets_manager_instance_crn` is set."
+ }
}
variable "use_existing_admin_pass_secret_manager_secret_group" {
@@ -336,4 +380,11 @@ variable "admin_pass_secret_manager_secret_name" {
type = string
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 `-` format."
default = "mongodb-admin-password"
+ validation {
+ condition = (
+ var.existing_secrets_manager_instance_crn == null ||
+ var.admin_pass_secret_manager_secret_name != null
+ )
+ error_message = "`admin_pass_secret_manager_secret_name` is required when `existing_secrets_manager_instance_crn` is set."
+ }
}
diff --git a/solutions/standard/version.tf b/solutions/standard/version.tf
index eca283f3..3f303f17 100644
--- a/solutions/standard/version.tf
+++ b/solutions/standard/version.tf
@@ -1,5 +1,5 @@
terraform {
- required_version = ">= 1.3.0"
+ required_version = ">= 1.9.0"
# Lock DA into an exact provider version - renovate automation will keep it updated
required_providers {
ibm = {
diff --git a/variables.tf b/variables.tf
index bc918c5e..63cd446e 100644
--- a/variables.tf
+++ b/variables.tf
@@ -186,6 +186,37 @@ variable "use_ibm_owned_encryption_key" {
type = bool
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."
default = true
+
+ validation {
+ condition = !(
+ var.use_ibm_owned_encryption_key == true &&
+ (var.kms_key_crn != null || var.backup_encryption_key_crn != null)
+ )
+ error_message = "When 'use_ibm_owned_encryption_key' is true, 'kms_key_crn' and 'backup_encryption_key_crn' must both be null."
+ }
+
+ validation {
+ condition = var.use_ibm_owned_encryption_key || var.kms_key_crn != null
+ error_message = "When setting 'use_ibm_owned_encryption_key' to false, a value must be passed for 'kms_key_crn'."
+ }
+
+ validation {
+ condition = (
+ 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)
+ )
+ 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."
+ }
+
+ validation {
+ condition = (
+ var.use_ibm_owned_encryption_key ||
+ var.backup_encryption_key_crn != null ||
+ var.use_same_kms_key_for_backups
+ )
+ error_message = "When 'use_same_kms_key_for_backups' is set to false, a value needs to be passed for 'backup_encryption_key_crn'."
+ }
}
variable "use_default_backup_encryption_key" {
diff --git a/version.tf b/version.tf
index 03b11d97..c783166c 100644
--- a/version.tf
+++ b/version.tf
@@ -1,5 +1,5 @@
terraform {
- required_version = ">= 1.3.0"
+ required_version = ">= 1.9.0"
required_providers {
# Use "greater than or equal to" range in modules
ibm = {