Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ You need the following permissions to run this module.

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.9.0 |
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.70.0, <2.0.0 |
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.9.1, < 1.0.0 |

Expand Down
11 changes: 0 additions & 11 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,6 @@
##############################################################################

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

# 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.

# If 'use_ibm_owned_encryption_key' is true or 'use_default_backup_encryption_key' is true, default to null.
# If no value is passed for 'backup_encryption_key_crn', then default to use 'kms_key_crn'.
Expand Down
2 changes: 1 addition & 1 deletion modules/fscloud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The IBM Cloud Framework for Financial Services mandates the application of an in

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.9.0 |
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >=1.70.0, <2.0.0 |

### Modules
Expand Down
2 changes: 1 addition & 1 deletion modules/fscloud/version.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 1.3.0"
required_version = ">= 1.9.0"
required_providers {
# The below tflint-ignore is required because although the below provider is not directly required by this submodule,
# it is required by consuming modules, and if not set here, the top level module calling this module will not be
Expand Down
17 changes: 0 additions & 17 deletions solutions/standard/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.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
#######################################################################################################################
Expand Down Expand Up @@ -317,9 +303,6 @@ locals {
existing_secrets_manager_instance_crn_split = var.existing_secrets_manager_instance_crn != null ? split(":", var.existing_secrets_manager_instance_crn) : null
existing_secrets_manager_instance_guid = var.existing_secrets_manager_instance_crn != null ? element(local.existing_secrets_manager_instance_crn_split, length(local.existing_secrets_manager_instance_crn_split) - 3) : null
existing_secrets_manager_instance_region = var.existing_secrets_manager_instance_crn != null ? element(local.existing_secrets_manager_instance_crn_split, length(local.existing_secrets_manager_instance_crn_split) - 5) : null

# tflint-ignore: terraform_unused_declarations
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
}

module "secrets_manager_service_credentials" {
Expand Down
13 changes: 13 additions & 0 deletions solutions/standard/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ 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 = alltrue([
!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),
var.use_ibm_owned_encryption_key || (var.existing_kms_instance_crn != null || var.existing_kms_key_crn != null)
])
error_message = "If ibm owned encryption is used then existing_kms_instance_crn and existing_kms_key_crn should be null. If not, 'existing_kms_instance_crn' or 'existing_kms_key_crn' or 'existing_backup_kms_key_crn' should be specified"
}
}

variable "existing_kms_instance_crn" {
Expand Down Expand Up @@ -263,6 +271,11 @@ variable "existing_secrets_manager_instance_crn" {
type = string
default = null
description = "The CRN of existing secrets manager to use to create service credential secrets for Databases for Redis instance."

validation {
condition = (length(var.service_credential_secrets) == 0 || var.existing_secrets_manager_instance_crn != null)
error_message = "'existing_secrets_manager_instance_crn' should be provided if there are 'service_credential_secrets'"
}
}

variable "existing_secrets_manager_endpoint_type" {
Expand Down
2 changes: 1 addition & 1 deletion solutions/standard/version.tf
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
11 changes: 11 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ variable "use_default_backup_encryption_key" {
type = bool
description = "When `use_ibm_owned_encryption_key` is set to false, backups will be encrypted with either the key specified in `kms_key_crn`, or in `backup_encryption_key_crn` if a value is passed. If you do not want to use your own key for backups encryption, you can set this to `true` to use the IBM Cloud Databases default encryption for backups. Alternatively set `use_ibm_owned_encryption_key` to true to use the default encryption for both backups and deployment data."
default = false

validation {

condition = alltrue([
!var.use_ibm_owned_encryption_key || (var.kms_key_crn == null && var.backup_encryption_key_crn == null),
var.use_ibm_owned_encryption_key || var.kms_key_crn != null,
(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),
(var.use_ibm_owned_encryption_key || var.backup_encryption_key_crn == null) || (!var.use_same_kms_key_for_backups)
])
error_message = "If IBM owned encryption is used then 'kms_key_crn' and 'backup_encryption_key_crn' should be null. If not, 'kms_key_crn' should be provided and if 'backup_encryption_key_crn' is not provided 'use_same_kms_key_for_backups' or 'use_default_backup_encryption_key' should be true.If 'backup_encryption_key_crn' is provided then 'use_same_kms_key_for_backups' should be set to false"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely not as readable as the mysql solution.

From a consumability perspective this is confusing, there are four different tests, some of them do not even reference use_default_backup_encryption_key. Having four validations, with four specific error messages is more helpful to the consumer. Also having all validation on one of the variables in the validation is more helpful from an on going maintenance perspective.

I am not entirely getting the implications of the alltrue block. I do not think there is any difference to having 4 conditions, they must inherently all be true, because any one that was false would trigger a more specific error message.

}
}

variable "kms_key_crn" {
Expand Down
2 changes: 1 addition & 1 deletion version.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 1.3.0"
required_version = ">= 1.9.0"
required_providers {
ibm = {
source = "IBM-Cloud/ibm"
Expand Down