Skip to content

Commit a2217e3

Browse files
fix(deps): updated required terraform version to >= 1.9.0 and updated variable validation logic (#636)
1 parent bb117bc commit a2217e3

File tree

14 files changed

+85
-32
lines changed

14 files changed

+85
-32
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ To attach access management tags to resources in this module, you need the follo
6363

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

examples/backup/version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 1.3.0"
2+
required_version = ">= 1.9.0"
33
required_providers {
44
# Ensure that there is always 1 example locked into the lowest provider version of the range defined in the main
55
# module's version.tf (basic example), and 1 example that will always use the latest provider version (complete example).

examples/basic/version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 1.3.0"
2+
required_version = ">= 1.9.0"
33
required_providers {
44
# Ensure that there is always 1 example locked into the lowest provider version of the range defined in the main
55
# module's version.tf (basic example), and 1 example that will always use the latest provider version (complete example).

examples/complete/version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 1.3.0"
2+
required_version = ">= 1.9.0"
33
required_providers {
44
# Ensure that there is always 1 example locked into the lowest provider version of the range defined in the main
55
# module's version.tf (basic example), and 1 example that will always use the latest provider version (complete example).

examples/fscloud/version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 1.3.0"
2+
required_version = ">= 1.9.0"
33
required_providers {
44
# Ensure that there is always 1 example locked into the lowest provider version of the range defined in the main
55
# module's version.tf (basic example), and 1 example that will always use the latest provider version (complete example).

examples/pitr/version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 1.3.0"
2+
required_version = ">= 1.9.0"
33
required_providers {
44
# Ensure that there is always 1 example locked into the lowest provider version of the range defined in the main
55
# module's version.tf (basic example), and 1 example that will always use the latest provider version (complete example).

main.tf

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@
88
########################################################################################################################
99

1010
locals {
11-
# Validation (approach based on https://github.com/hashicorp/terraform/issues/25609#issuecomment-1057614400)
12-
# tflint-ignore: terraform_unused_declarations
13-
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
14-
# tflint-ignore: terraform_unused_declarations
15-
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
16-
# tflint-ignore: terraform_unused_declarations
17-
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
18-
# tflint-ignore: terraform_unused_declarations
19-
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
20-
# tflint-ignore: terraform_unused_declarations
21-
validate_pitr_vars = (var.pitr_id != null && var.pitr_time == null) || (var.pitr_time != null && var.pitr_id == null) ? tobool("To use Point-In-Time Recovery (PITR), values for both var.pitr_id and var.pitr_time need to be set. Otherwise, unset both of these.") : true
2211

2312
# If 'use_ibm_owned_encryption_key' is true or 'use_default_backup_encryption_key' is true, default to null.
2413
# If no value is passed for 'backup_encryption_key_crn', then default to use 'kms_key_crn'.

modules/fscloud/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The IBM Cloud Framework for Financial Services mandates the application of an in
1111

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

1717
### Modules

modules/fscloud/version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 1.3.0"
2+
required_version = ">= 1.9.0"
33
required_providers {
44
# The below tflint-ignore is required because although the below provider is not directly required by this submodule,
55
# it is required by consuming modules, and if not set here, the top level module calling this module will not be

solutions/standard/main.tf

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ module "resource_group" {
1616
# TODO: Replace with terraform cross variable validation: https://github.ibm.com/GoldenEye/issues/issues/10836
1717
#######################################################################################################################
1818

19-
locals {
20-
# tflint-ignore: terraform_unused_declarations
21-
validate_kms_1 = var.existing_postgresql_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_postgresql_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
24-
}
25-
2619
#######################################################################################################################
2720
# KMS encryption key
2821
#######################################################################################################################
@@ -254,10 +247,6 @@ module "postgresql_instance_crn_parser" {
254247
locals {
255248
existing_postgresql_guid = var.existing_postgresql_instance_crn != null ? module.postgresql_instance_crn_parser[0].service_instance : null
256249
existing_postgresql_region = var.existing_postgresql_instance_crn != null ? module.postgresql_instance_crn_parser[0].region : null
257-
258-
# 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_postgresql_instance_crn != null && var.region != local.existing_postgresql_region ? tobool("The region detected in the 'existing_postgresql_instance_crn' value must match the value of the 'region' input variable when passing an existing instance.") : true
261250
}
262251

263252
# Do a data lookup on the resource GUID to get more info that is needed for the 'ibm_database' data lookup below

solutions/standard/variables.tf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ variable "region" {
4646
description = "The region where you want to deploy your instance."
4747
type = string
4848
default = "us-south"
49+
50+
validation {
51+
condition = var.existing_postgresql_instance_crn != null && var.region != local.existing_postgresql_region ? false : true
52+
error_message = "The region detected in the 'existing_postgresql_instance_crn' value must match the value of the 'region' input variable when passing an existing instance."
53+
}
4954
}
5055

5156
variable "pg_version" {
@@ -58,6 +63,14 @@ variable "backup_crn" {
5863
type = string
5964
description = "The CRN of a backup resource to restore from. The backup is created by a database deployment with the same service ID. The backup is loaded after provisioning and the new deployment starts up that uses that data. A backup CRN is in the format crn:v1:<…>:backup:. If omitted, the database is provisioned empty."
6065
default = null
66+
67+
validation {
68+
condition = anytrue([
69+
var.backup_crn == null,
70+
can(regex("^crn:.*:backup:", var.backup_crn))
71+
])
72+
error_message = "backup_crn must be null OR starts with 'crn:' and contains ':backup:'"
73+
}
6174
}
6275

6376
variable "remote_leader_crn" {
@@ -224,6 +237,30 @@ variable "use_ibm_owned_encryption_key" {
224237
type = bool
225238
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."
226239
default = false
240+
241+
# this validation ensures IBM-owned key is not used when KMS details are provided
242+
validation {
243+
condition = (
244+
var.existing_postgresql_instance_crn != null ||
245+
!(var.use_ibm_owned_encryption_key && (
246+
var.existing_kms_instance_crn != null ||
247+
var.existing_kms_key_crn != null ||
248+
var.existing_backup_kms_key_crn != null
249+
))
250+
)
251+
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."
252+
}
253+
254+
# this validation ensures key info is provided when IBM-owned key is disabled and no Postgresql instance is given
255+
validation {
256+
condition = !(
257+
var.existing_postgresql_instance_crn == null &&
258+
var.use_ibm_owned_encryption_key == false &&
259+
var.existing_kms_instance_crn == null &&
260+
var.existing_kms_key_crn == null
261+
)
262+
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)."
263+
}
227264
}
228265

229266
variable "existing_kms_instance_crn" {

solutions/standard/version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 1.3.0"
2+
required_version = ">= 1.9.0"
33

44
# Lock DA into an exact provider version - renovate automation will keep it updated
55
required_providers {

variables.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,34 @@ variable "use_ibm_owned_encryption_key" {
258258
type = bool
259259
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."
260260
default = true
261+
262+
validation {
263+
condition = var.use_ibm_owned_encryption_key && (var.kms_key_crn != null || var.backup_encryption_key_crn != null) ? false : true
264+
error_message = "When 'use_ibm_owned_encryption_key' is true, 'kms_key_crn' and 'backup_encryption_key_crn' must both be null."
265+
}
266+
267+
validation {
268+
condition = var.use_ibm_owned_encryption_key || var.kms_key_crn != null
269+
error_message = "When setting 'use_ibm_owned_encryption_key' to false, a value must be passed for 'kms_key_crn'."
270+
}
271+
272+
validation {
273+
condition = (
274+
var.use_ibm_owned_encryption_key ||
275+
var.backup_encryption_key_crn == null ||
276+
(!var.use_default_backup_encryption_key && !var.use_same_kms_key_for_backups)
277+
)
278+
error_message = "When passing a value for backup_encryption_key_crn, you should set use_same_kms_key_for_backups to false, use_default_backup_encryption_key to false and use_ibm_owned_encryption_key to false."
279+
}
280+
281+
validation {
282+
condition = (
283+
var.use_ibm_owned_encryption_key ||
284+
var.backup_encryption_key_crn != null ||
285+
var.use_same_kms_key_for_backups
286+
)
287+
error_message = "When 'use_same_kms_key_for_backups' is set to false, a value needs to be passed for 'backup_encryption_key_crn'."
288+
}
261289
}
262290

263291
variable "kms_key_crn" {
@@ -358,6 +386,16 @@ variable "pitr_id" {
358386
type = string
359387
description = "(Optional) The ID of the source deployment PostgreSQL instance that you want to recover back to. The PostgreSQL instance is expected to be in an up and in running state."
360388
default = null
389+
390+
validation {
391+
condition = var.pitr_id != null ? true : var.pitr_time == null
392+
error_message = "To use Point-In-Time Recovery (PITR), a value for var.pitr_id needs to be set when var.pitr_time is specified. Otherwise, unset var.pitr_time."
393+
}
394+
395+
validation {
396+
condition = var.pitr_id == null ? true : var.pitr_time != null
397+
error_message = "To use Point-In-Time Recovery (PITR), a value for var.pitr_time needs to be set when var.pitr_id is specified. Otherwise, unset var.pitr_id."
398+
}
361399
}
362400

363401
variable "pitr_time" {

version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 1.3.0"
2+
required_version = ">= 1.9.0"
33
required_providers {
44
# Use "greater than or equal to" range in modules
55
ibm = {

0 commit comments

Comments
 (0)