Skip to content

Commit 72abd6e

Browse files
authored
feat: updated required terraform version to >= 1.9.0 + updated variable validation logic (#655)
1 parent c19e81d commit 72abd6e

File tree

8 files changed

+21
-23
lines changed

8 files changed

+21
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ For more info, see [Understanding user roles and resources](https://cloud.ibm.co
140140

141141
| Name | Version |
142142
|------|---------|
143-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
143+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.9.0 |
144144
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.76.0, <2.0.0 |
145145

146146
### Modules

examples/advanced/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.0.0"
2+
required_version = ">= 1.9.0"
33

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 (this 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.0.0"
2+
required_version = ">= 1.9.0"
33

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 (this example), and 1 example that will always use the latest provider version (existing resources example).

examples/existing-resources/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.0.0"
2+
required_version = ">= 1.9.0"
33

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 (this example).

main.tf

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,11 @@
33
##############################################################################
44

55
locals {
6-
# variable validation around resource_group_id
7-
rg_validate_condition = var.create_key_protect_instance && var.resource_group_id == null
8-
rg_validate_msg = "A value must be passed for 'resource_group_id' when 'create_key_protect_instance' is true"
9-
# tflint-ignore: terraform_unused_declarations
10-
rg_validate_check = regex("^${local.rg_validate_msg}$", (!local.rg_validate_condition ? local.rg_validate_msg : ""))
116

127
parsed_existing_kms_instance_crn = var.existing_kms_instance_crn != null ? split(":", var.existing_kms_instance_crn) : []
138
existing_kms_instance_guid = length(local.parsed_existing_kms_instance_crn) > 0 ? local.parsed_existing_kms_instance_crn[7] : null
149
existing_kms_account_id = length(local.parsed_existing_kms_instance_crn) > 0 ? split("/", local.parsed_existing_kms_instance_crn[6])[1] : null
1510

16-
# variable validation around new instance vs existing
17-
instance_validate_condition = var.create_key_protect_instance && local.existing_kms_instance_guid != null
18-
instance_validate_msg = "'create_key_protect_instance' cannot be true when passing a value for 'existing_key_protect_instance_guid'"
19-
# tflint-ignore: terraform_unused_declarations
20-
instance_validate_check = regex("^${local.instance_validate_msg}$", (!local.instance_validate_condition ? local.instance_validate_msg : ""))
21-
22-
# variable validation when not creating new instance
23-
existing_instance_validate_condition = !var.create_key_protect_instance && local.existing_kms_instance_guid == null
24-
existing_instance_validate_msg = "A value must be provided for 'existing_key_protect_instance_guid' when 'create_key_protect_instance' is false"
25-
# tflint-ignore: terraform_unused_declarations
26-
existing_instance_validate_check = regex("^${local.existing_instance_validate_msg}$", (!local.existing_instance_validate_condition ? local.existing_instance_validate_msg : ""))
27-
2811
# set key_protect_guid as either the ID of the passed in name of instance or the one created by this module
2912
kms_guid = var.create_key_protect_instance ? module.key_protect[0].key_protect_guid : local.existing_kms_instance_guid
3013

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
# Lock DA into an exact provider version - renovate automation will keep it updated
44
required_providers {
55
ibm = {

variables.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ variable "create_key_protect_instance" {
1717
type = bool
1818
description = "A flag to control whether a Key Protect instance is created, defaults to true."
1919
default = true
20+
21+
validation {
22+
condition = !var.create_key_protect_instance || var.resource_group_id != null
23+
error_message = "A value must be passed for 'resource_group_id' when 'create_key_protect_instance' is true"
24+
}
2025
}
2126

2227
variable "key_protect_instance_name" {
@@ -88,6 +93,16 @@ variable "existing_kms_instance_crn" {
8893
type = string
8994
description = "The CRN of an existing Key Protect or Hyper Protect Crypto Services instance. Required if 'create_key_protect_instance' is false."
9095
default = null
96+
97+
validation {
98+
condition = !(var.create_key_protect_instance && var.existing_kms_instance_crn != null)
99+
error_message = "'create_key_protect_instance' cannot be true when passing a value for 'existing_kms_instance_crn'"
100+
}
101+
102+
validation {
103+
condition = var.create_key_protect_instance || var.existing_kms_instance_crn != null
104+
error_message = "A value must be provided for 'existing_kms_instance_crn' when 'create_key_protect_instance' is false"
105+
}
91106
}
92107

93108
variable "keys" {

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.0.0"
2+
required_version = ">= 1.9.0"
33

44
# Each required provider's version should be a flexible range to future proof the module's usage with upcoming minor and patch versions.
55
required_providers {

0 commit comments

Comments
 (0)