Skip to content

Commit 72f7274

Browse files
arya-girish-kArya Girish KAk-sky
authored
feat: improved user experience for validating input variable values <br> - updated required terraform to be >= 1.9.0 (#419)
* add: cross-object referencing for input variable validation * reverted validations * Update solutions/standard/variables.tf Co-authored-by: Akash Kumar <Ak-sky@users.noreply.github.com> * fix: resolved pre-commit error --------- Co-authored-by: Arya Girish K <arya.girish.k@ibm.com> Co-authored-by: Akash Kumar <Ak-sky@users.noreply.github.com>
1 parent 1e83f24 commit 72f7274

File tree

11 files changed

+32
-25
lines changed

11 files changed

+32
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ To create service credentials, access the Event Notifications service, and acces
6868

6969
| Name | Version |
7070
|------|---------|
71-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
71+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.9.0 |
7272
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.76.0, < 2.0.0 |
7373
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.9.1 |
7474

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

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 (usually a basic example), and 1 example that will always use the latest provider version.

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

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 (usually a basic example), and 1 example that will always use the latest provider version.

main.tf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# This file creates an event notificaiton resource instance
33
###########################################################
44
locals {
5-
# tflint-ignore: terraform_unused_declarations
6-
validate_kms_plan = var.kms_encryption_enabled && var.plan != "standard" ? tobool("kms encryption is only supported for standard plan") : true
75
# tflint-ignore: terraform_unused_declarations
86
validate_kms_values = !var.kms_encryption_enabled && (var.existing_kms_instance_crn != null || var.root_key_id != null || var.kms_endpoint_url != null) ? tobool("When passing values for var.existing_kms_instance_crn or/and var.root_key_id or/and var.kms_endpoint_url, you must set var.kms_encryption_enabled to true. Otherwise unset them to use default encryption") : true
97
# tflint-ignore: terraform_unused_declarations
@@ -12,7 +10,6 @@ locals {
1210
validate_cos_values = !var.cos_integration_enabled && (var.cos_instance_id != null || var.cos_bucket_name != null || var.cos_endpoint != null) ? tobool("When passing values for var.cos_instance_id or/and var.cos_bucket_name or/and var.cos_endpoint, you must set var.cos_integration_enabled to true. Otherwise unset them to disable collection of failed delivery events") : true
1311
# tflint-ignore: terraform_unused_declarations
1412
validate_cos_vars = var.cos_integration_enabled && (var.cos_instance_id == null || var.cos_bucket_name == null || var.cos_endpoint == null) ? tobool("When setting var.cos_integration_enabled to true, a value must be passed for var.cos_instance_id, var.cos_bucket_name and var.cos_endpoint") : true
15-
1613
# Determine what KMS service is being used for encryption
1714
kms_service = var.existing_kms_instance_crn != null ? (
1815
can(regex(".*kms.*", var.existing_kms_instance_crn)) ? "kms" : (

modules/fscloud/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module "event_notification" {
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.76.0, <2.0.0 |
6868

6969
### 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: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ module "resource_group" {
1717

1818
# Input variable validation
1919
locals {
20-
# Validate that a value has been passed for 'existing_kms_instance_crn' and 'kms_endpoint_url' if not using existing EN instance
21-
# tflint-ignore: terraform_unused_declarations
22-
validate_kms_input = (var.existing_kms_instance_crn == null || var.kms_endpoint_url == null) && var.existing_en_instance_crn == null ? tobool("A value for 'existing_kms_instance_crn' and 'kms_endpoint_url' must be passed when no value is passed for 'existing_en_instance_crn'.") : true
23-
prefix = var.prefix != null ? (var.prefix != "" ? var.prefix : null) : null
20+
prefix = var.prefix != null ? (var.prefix != "" ? var.prefix : null) : null
2421
}
2522

2623
# If existing KMS root key CRN passed, parse details from it
@@ -222,14 +219,6 @@ module "cos_instance_crn_parser" {
222219
}
223220

224221
locals {
225-
# Validate mutually exclusive inputs
226-
# tflint-ignore: terraform_unused_declarations
227-
validate_cos_regions = var.cos_bucket_region != null && var.cross_region_location != null ? tobool("Cannot provide values for 'cos_bucket_region' and 'cross_region_location'. Pick one or the other, or alternatively pass no values for either and allow it to default to the 'region' input.") : true
228-
229-
# Validate cos inputs when using existing bucket
230-
# tflint-ignore: terraform_unused_declarations
231-
validate_cos_bucket = var.existing_cos_bucket_name != null && (var.existing_cos_instance_crn == null || var.existing_cos_endpoint == null) ? tobool("When passing a value for 'existing_cos_bucket_name', you must also pass values for 'existing_cos_instance_crn' and 'existing_cos_endpoint'.") : true
232-
233222
# If a bucket name is passed, or an existing EN CRN is passed; do not create COS resources
234223
create_cos_bucket = var.existing_cos_bucket_name != null || var.existing_en_instance_crn != null ? false : true
235224
# determine COS details
@@ -340,9 +329,6 @@ module "existing_sm_crn_parser" {
340329
}
341330

342331
locals {
343-
# Validate that a value has been passed for 'existing_secrets_manager_instance_crn' if creating credentials using the 'service_credential_secrets' input
344-
# tflint-ignore: terraform_unused_declarations
345-
validate_sm_crn = length(var.service_credential_secrets) > 0 && var.existing_secrets_manager_instance_crn == null ? tobool("'existing_secrets_manager_instance_crn' is required when adding service credentials with the 'service_credential_secrets' input.") : false
346332
# parse SM GUID from CRN
347333
existing_secrets_manager_instance_guid = var.existing_secrets_manager_instance_crn != null ? module.existing_sm_crn_parser[0].service_instance : null
348334
# parse SM region from CRN

solutions/standard/variables.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ variable "existing_kms_instance_crn" {
118118
type = string
119119
description = "The CRN of the KMS instance (Hyper Protect Crypto Services or Key Protect instance). If the KMS instance is in different account you must also provide a value for `ibmcloud_kms_api_key`."
120120
default = null
121+
validation {
122+
condition = var.existing_en_instance_crn == null ? (var.existing_kms_instance_crn != null && var.kms_endpoint_url != null) : true
123+
error_message = ("A value for 'existing_kms_instance_crn' and 'kms_endpoint_url' must be passed when no value is passed for 'existing_en_instance_crn'.")
124+
}
121125
}
122126

123127
variable "existing_kms_root_key_crn" {
@@ -195,6 +199,12 @@ variable "existing_cos_bucket_name" {
195199
nullable = true
196200
default = null
197201
description = "The name of an existing bucket inside the existing Object Storage instance. If not supplied, a new bucket is created."
202+
203+
validation {
204+
condition = var.existing_cos_bucket_name != null ? (var.existing_cos_instance_crn != null && var.existing_cos_endpoint != null) : true
205+
error_message = "When passing a value for 'existing_cos_bucket_name', you must also pass values for 'existing_cos_instance_crn' and 'existing_cos_endpoint'."
206+
}
207+
198208
}
199209

200210
variable "cos_bucket_name" {
@@ -264,6 +274,11 @@ variable "cos_bucket_region" {
264274
type = string
265275
description = "The COS bucket region. If you pass a value for this variable, you must set the value of `cross_region_location` to null. If `cross_region_location` and `cos_bucket_region` are both set to null, then `region` will be used."
266276
default = null
277+
278+
validation {
279+
condition = var.cos_bucket_region == null || var.cross_region_location == null
280+
error_message = "Cannot provide values for both 'cos_bucket_region' and 'cross_region_location'. Pick one or the other, or alternatively, pass no value for either and allow it to default to the 'region' input."
281+
}
267282
}
268283

269284
variable "archive_days" {
@@ -356,6 +371,11 @@ variable "service_credential_secrets" {
356371
])
357372
error_message = "service_credentials_source_service_role_crn must be a serviceRole CRN. See https://cloud.ibm.com/iam/roles"
358373
}
374+
validation {
375+
condition = length(var.service_credential_secrets) > 0 ? var.existing_secrets_manager_instance_crn != null : true
376+
error_message = "'existing_secrets_manager_instance_crn' is required when adding service credentials with the 'service_credential_secrets' input."
377+
}
378+
359379
}
360380

361381
variable "skip_en_sm_auth_policy" {

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ variable "kms_encryption_enabled" {
114114
type = bool
115115
description = "Set to `true` to control the encryption keys that are used to encrypt the data that you store in the Event Notifications instance. If set to `false`, the data is encrypted by using randomly generated keys. For more information, see [Managing encryption](https://cloud.ibm.com/docs/event-notifications?topic=event-notifications-en-managing-encryption)."
116116
default = false
117+
validation {
118+
condition = var.kms_encryption_enabled == false || var.plan == "standard"
119+
error_message = "kms encryption is only supported for standard plan"
120+
}
117121
}
118122

119123
variable "skip_en_cos_auth_policy" {

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
# Use a flexible range in modules that future proofs the module's usage with upcoming minor and patch versions
55
required_providers {

0 commit comments

Comments
 (0)