Skip to content

Commit 96b02eb

Browse files
authored
feat: improved user experience for validating input variable values<br> * updated required terraform to be >= 1.9.0 (#301)
1 parent 56a9280 commit 96b02eb

File tree

10 files changed

+41
-21
lines changed

10 files changed

+41
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ You need the following permissions to run this module.
188188

189189
| Name | Version |
190190
|------|---------|
191-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
191+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.9.0 |
192192
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.49.0, < 2.0.0 |
193193
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 2.4.0, < 3.0.0 |
194194

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/hybrid-hpcs/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 & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@ This file is used to implement the HPCS module.
33
*********************************************************************/
44

55
locals {
6-
# tflint-ignore: terraform_unused_declarations
7-
validate_inputs = var.hsm_connector_id != null && var.auto_initialization_using_recovery_crypto_units == true ? tobool("Provided inputs are not correct. If hsm_conector_id is set to a value then auto_initialization_using_recovery_crypto_units can not be true.") : true
8-
# tflint-ignore: terraform_unused_declarations
9-
validate_region = var.auto_initialization_using_recovery_crypto_units == true ? (contains(["us-south", "us-east"], var.region) ? true : tobool("Currently us-south and us-east are the only supported regions for HPCS instance initialization using recovery crypto units.")) : true
10-
# tflint-ignore: terraform_unused_declarations
11-
validate_num_of_administrators = var.auto_initialization_using_recovery_crypto_units == true ? ((length(var.admins) >= 1 && length(var.admins) <= 8) || (length(var.base64_encoded_admins) >= 1 && length(var.base64_encoded_admins) <= 8) ? true : tobool("At least one administrator is required for the instance crypto unit and you can set upto 8 adminsitrators.")) : true
12-
# tflint-ignore: terraform_unused_declarations
13-
validate_admins_and_threshold = var.auto_initialization_using_recovery_crypto_units == true ? (((length(var.admins) >= var.signature_threshold) || (length(var.base64_encoded_admins) >= var.signature_threshold) && (length(var.admins) >= var.revocation_threshold) || (length(var.base64_encoded_admins) >= var.revocation_threshold)) ? true : tobool("The adminstrators of the instance crypto units need to be equal to or greater than the threshold value.")) : true
14-
# tflint-ignore: terraform_unused_declarations
15-
validate_num_of_failover_units = var.auto_initialization_using_recovery_crypto_units == true ? (var.number_of_failover_units <= var.number_of_crypto_units ? true : tobool("Number of failover_units must be less than or equal to the number of operational crypto units")) : true
16-
# tflint-ignore: terraform_unused_declarations
17-
validate_admins_variables = var.auto_initialization_using_recovery_crypto_units == true ? ((length(var.admins) == 0 && length(var.base64_encoded_admins) == 0) || (length(var.admins) != 0 && length(var.base64_encoded_admins) != 0) ? tobool("Please provide exactly one of admins or base64_encoded_admins. Passing neither or both is invalid.") : true) : true
18-
196
admins_name_map = merge([for admin in var.base64_encoded_admins : { (admin.name) = { "name" = admin.name } }]...) # map created for non-sensitive value (admin name) only
207
admins_map = length(var.base64_encoded_admins) != 0 ? { for admin in var.base64_encoded_admins : admin.name => admin } : null
218
admins = local.admins_map != null ? [

modules/fscloud/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ As a result, several manual steps must be taken after deploying and initializing
1616

1717
| Name | Version |
1818
|------|---------|
19-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
19+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.9.0 |
2020

2121
### Modules
2222

modules/fscloud/version.tf

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

variables.tf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ variable "resource_group_id" {
1010
variable "region" {
1111
type = string
1212
description = "The region where you want to deploy your instance."
13+
14+
validation {
15+
condition = var.auto_initialization_using_recovery_crypto_units != true || contains(["us-south", "us-east"], var.region)
16+
error_message = "Currently us-south and us-east are the only supported regions for HPCS instance initialization using recovery crypto units."
17+
}
1318
}
1419

1520
variable "name" {
@@ -89,6 +94,22 @@ variable "admins" {
8994
default = []
9095
sensitive = true
9196
description = "A list of administrators for the instance crypto units. See [instructions](https://github.com/terraform-ibm-modules/terraform-ibm-hpcs#before-you-begin) to create administrator signature keys. You can set up to 8 administrators. Required if auto_initialization_using_recovery_crypto_units set to true. "
97+
98+
validation {
99+
condition = var.auto_initialization_using_recovery_crypto_units != true || ((length(var.admins) >= 1 && length(var.admins) <= 8) || (length(var.base64_encoded_admins) >= 1 && length(var.base64_encoded_admins) <= 8))
100+
error_message = "At least one administrator is required for the instance crypto unit and you can set upto 8 adminsitrators."
101+
}
102+
103+
validation {
104+
condition = var.auto_initialization_using_recovery_crypto_units != true || ((length(var.admins) >= var.signature_threshold || length(var.base64_encoded_admins) >= var.signature_threshold) && (length(var.admins) >= var.revocation_threshold || length(var.base64_encoded_admins) >= var.revocation_threshold))
105+
error_message = "The adminstrators of the instance crypto units need to be equal to or greater than the threshold value."
106+
}
107+
108+
validation {
109+
condition = var.auto_initialization_using_recovery_crypto_units != true || !((length(var.admins) == 0 && length(var.base64_encoded_admins) == 0) || (length(var.admins) != 0 && length(var.base64_encoded_admins) != 0))
110+
error_message = "Please provide exactly one of admins or base64_encoded_admins. Passing neither or both is invalid."
111+
}
112+
92113
}
93114

94115
variable "base64_encoded_admins" {
@@ -110,6 +131,13 @@ variable "number_of_failover_units" {
110131
condition = contains([0, 2, 3], var.number_of_failover_units)
111132
error_message = "Allowed values of failover_units is 0, 2, 3."
112133
}
134+
135+
validation {
136+
137+
condition = var.auto_initialization_using_recovery_crypto_units != true || (var.number_of_failover_units <= var.number_of_crypto_units)
138+
error_message = "Number of failover_units must be less than or equal to the number of operational crypto units"
139+
140+
}
113141
}
114142

115143
variable "service_endpoints" {
@@ -127,6 +155,11 @@ variable "hsm_connector_id" {
127155
type = string
128156
description = "The HSM connector ID provided by IBM required for Hybrid HPCS. Available to selected customers only."
129157
default = null
158+
159+
validation {
160+
condition = var.hsm_connector_id == null || var.auto_initialization_using_recovery_crypto_units != true
161+
error_message = "Provided inputs are not correct. If hsm_connector_id is set to a value then auto_initialization_using_recovery_crypto_units cannot be true."
162+
}
130163
}
131164

132165
variable "create_timeout" {

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
required_providers {
55
# Use "greater than or equal to" range in modules

0 commit comments

Comments
 (0)