Skip to content

Commit e2a5178

Browse files
feat: Added input variable validation to several input (#182)
1 parent a9216d7 commit e2a5178

File tree

7 files changed

+107
-53
lines changed

7 files changed

+107
-53
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ IBM `watsonx.ai` provides an enterprise-grade studio of integrated tools for dev
3131
* [configure_user](./modules/configure_user)
3232
* [storage_delegation](./modules/storage_delegation)
3333
* [Examples](./examples)
34-
* <div style="display: inline-block;"><a href="./examples/basic">Basic example</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=wa-basic-example&repository=github.com/terraform-ibm-modules/terraform-ibm-watsonx-ai/tree/main/examples/basic" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
35-
* <div style="display: inline-block;"><a href="./examples/complete">Complete example</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=wa-complete-example&repository=github.com/terraform-ibm-modules/terraform-ibm-watsonx-ai/tree/main/examples/complete" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
34+
* <div style="display: inline-block;"><a href="./examples/basic">Basic example</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=wa-basic-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-watsonx-ai/tree/main/examples/basic" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
35+
* <div style="display: inline-block;"><a href="./examples/complete">Complete example</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=wa-complete-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-watsonx-ai/tree/main/examples/complete" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
3636
* [Contributing](#contributing)
3737
<!-- END OVERVIEW HOOK -->
3838

ibm_catalog.json

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,14 @@
266266
},
267267
{
268268
"key": "existing_cos_instance_crn",
269-
"required": true
269+
"required": true,
270+
"value_constraints": [
271+
{
272+
"type": "regex",
273+
"description": "The value provided for 'existing_cos_instance_crn' is not valid.",
274+
"value": "^crn:v\\d:(.*:){2}cloud-object-storage:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$"
275+
}
276+
]
270277
},
271278
{
272279
"key": "enable_platform_metrics",
@@ -324,7 +331,14 @@
324331
"key": "watsonx_ai_studio_instance_name"
325332
},
326333
{
327-
"key": "existing_watsonx_ai_studio_instance_crn"
334+
"key": "existing_watsonx_ai_studio_instance_crn",
335+
"value_constraints": [
336+
{
337+
"type": "regex",
338+
"description": "The value provided for 'existing_watsonx_ai_studio_instance_crn' is not valid.",
339+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}data-science-experience:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$"
340+
}
341+
]
328342
},
329343
{
330344
"key": "watsonx_ai_runtime_instance_name"
@@ -350,7 +364,14 @@
350364
"key": "watsonx_ai_new_project_members"
351365
},
352366
{
353-
"key": "existing_watsonx_ai_runtime_instance_crn"
367+
"key": "existing_watsonx_ai_runtime_instance_crn",
368+
"value_constraints": [
369+
{
370+
"type": "regex",
371+
"description": "The value provided for 'existing_watsonx_ai_runtime_instance_crn' is not valid.",
372+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}pm-20:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$"
373+
}
374+
]
354375
},
355376
{
356377
"key": "resource_tags",
@@ -387,10 +408,24 @@
387408
"key": "skip_cos_kms_iam_auth_policy"
388409
},
389410
{
390-
"key": "existing_cos_kms_key_crn"
411+
"key": "existing_cos_kms_key_crn",
412+
"value_constraints": [
413+
{
414+
"type": "regex",
415+
"description": "The value provided for 'existing_cos_kms_key_crn' is not valid.",
416+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}kms:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}:key:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
417+
}
418+
]
391419
},
392420
{
393-
"key": "existing_kms_instance_crn"
421+
"key": "existing_kms_instance_crn",
422+
"value_constraints": [
423+
{
424+
"type": "regex",
425+
"description": "The value provided for 'existing_kms_instance_crn' is not valid.",
426+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}kms:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$"
427+
}
428+
]
394429
},
395430
{
396431
"key": "ibmcloud_kms_api_key"

solutions/fully-configurable/variables.tf

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ variable "existing_resource_group_name" {
2727

2828
variable "prefix" {
2929
type = string
30-
description = "The prefix to be added to all resources created by this solution. To skip using a prefix, set this value to null or an empty string. The prefix must begin with a lowercase letter and may contain only lowercase letters, digits, and hyphens '-'. It should not exceed 16 characters, must not end with a hyphen('-'), and can not contain consecutive hyphens ('--'). Example: wx-0205-ai. [Learn more](https://terraform-ibm-modules.github.io/documentation/#/prefix.md)."
30+
nullable = true
31+
description = "The prefix to add to all resources that this solution creates (e.g `prod`, `test`, `dev`). To skip using a prefix, set this value to null or an empty string. [Learn more](https://terraform-ibm-modules.github.io/documentation/#/prefix.md)."
3132

3233
validation {
3334
# - null and empty string is allowed
@@ -76,6 +77,14 @@ variable "existing_watsonx_ai_studio_instance_crn" {
7677
default = null
7778
description = "The CRN of an existing watsonx.ai Studio instance. If not provided, a new instance will be provisioned."
7879
type = string
80+
81+
validation {
82+
condition = anytrue([
83+
var.existing_watsonx_ai_studio_instance_crn == null,
84+
can(regex("^crn:v\\d:(.*:){2}data-science-experience:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$", var.existing_watsonx_ai_studio_instance_crn))
85+
])
86+
error_message = "The value provided for 'existing_watsonx_ai_studio_instance_crn' is not valid."
87+
}
7988
}
8089

8190
variable "watsonx_ai_studio_plan" {
@@ -102,6 +111,14 @@ variable "existing_watsonx_ai_runtime_instance_crn" {
102111
default = null
103112
description = "The CRN of an existing watsonx.ai Runtime instance. If not provided, a new instance will be provisioned."
104113
type = string
114+
115+
validation {
116+
condition = anytrue([
117+
var.existing_watsonx_ai_runtime_instance_crn == null,
118+
can(regex("^crn:v\\d:(.*:){2}pm-20:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$", var.existing_watsonx_ai_runtime_instance_crn))
119+
])
120+
error_message = "The value provided for 'existing_watsonx_ai_runtime_instance_crn' is not valid."
121+
}
105122
}
106123

107124
variable "watsonx_ai_runtime_instance_name" {
@@ -184,17 +201,25 @@ variable "existing_kms_instance_crn" {
184201

185202
validation {
186203
condition = anytrue([
187-
can(regex("^crn:(.*:){3}kms:(.*:){2}[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$", var.existing_kms_instance_crn)),
188204
var.existing_kms_instance_crn == null,
205+
can(regex("^crn:v\\d:(.*:){2}kms:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$", var.existing_kms_instance_crn))
189206
])
190-
error_message = "The provided KMS (Key Protect) instance CRN in not valid."
207+
error_message = "The value provided for 'existing_kms_instance_crn' is not valid."
191208
}
192209
}
193210

194211
variable "existing_cos_kms_key_crn" {
195212
type = string
196213
default = null
197214
description = "Optional. The CRN of an existing key management service (Key Protect) key to use to encrypt the Cloud Object Storage bucket that this solution creates. To create a key ring and key, pass a value for the `existing_kms_instance_crn` input variable."
215+
216+
validation {
217+
condition = anytrue([
218+
var.existing_cos_kms_key_crn == null,
219+
can(regex("^crn:v\\d:(.*:){2}kms:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}:key:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", var.existing_cos_kms_key_crn))
220+
])
221+
error_message = "The value provided for 'existing_cos_kms_key_crn' is not valid."
222+
}
198223
}
199224

200225
variable "kms_endpoint_type" {
@@ -244,6 +269,14 @@ variable "ibmcloud_kms_api_key" {
244269
variable "existing_cos_instance_crn" {
245270
type = string
246271
description = "The CRN of an existing Cloud Object Storage instance."
272+
273+
validation {
274+
condition = anytrue([
275+
var.existing_cos_instance_crn == null,
276+
can(regex("^crn:v\\d:(.*:){2}cloud-object-storage:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$", var.existing_cos_instance_crn))
277+
])
278+
error_message = "The value provided for 'existing_cos_instance_crn' is not valid."
279+
}
247280
}
248281

249282
variable "skip_cos_kms_iam_auth_policy" {

tests/go.mod

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ go 1.24.0
55
toolchain go1.25.4
66

77
require (
8-
github.com/IBM/go-sdk-core v1.1.0
9-
github.com/gruntwork-io/terratest v0.52.0
8+
github.com/IBM/go-sdk-core/v5 v5.21.0
9+
github.com/gruntwork-io/terratest v0.53.0
1010
github.com/stretchr/testify v1.11.1
11-
github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper v1.60.22
11+
github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper v1.60.32
1212
)
1313

1414
require (
1515
dario.cat/mergo v1.0.0 // indirect
1616
github.com/IBM-Cloud/bluemix-go v0.0.0-20240719075425-078fcb3a55be // indirect
1717
github.com/IBM-Cloud/power-go-client v1.13.0 // indirect
1818
github.com/IBM/cloud-databases-go-sdk v0.8.1 // indirect
19-
github.com/IBM/go-sdk-core/v5 v5.21.0 // indirect
2019
github.com/IBM/platform-services-go-sdk v0.90.0 // indirect
2120
github.com/IBM/project-go-sdk v0.3.9 // indirect
2221
github.com/IBM/schematics-go-sdk v0.4.0 // indirect
@@ -29,7 +28,6 @@ require (
2928
github.com/cloudflare/circl v1.6.1 // indirect
3029
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
3130
github.com/davecgh/go-spew v1.1.1 // indirect
32-
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
3331
github.com/emirpasic/gods v1.18.1 // indirect
3432
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
3533
github.com/ghodss/yaml v1.0.0 // indirect
@@ -92,14 +90,13 @@ require (
9290
go.opentelemetry.io/otel/metric v1.35.0 // indirect
9391
go.opentelemetry.io/otel/trace v1.35.0 // indirect
9492
go.yaml.in/yaml/v2 v2.4.2 // indirect
95-
golang.org/x/crypto v0.43.0 // indirect
96-
golang.org/x/mod v0.28.0 // indirect
93+
golang.org/x/crypto v0.44.0 // indirect
94+
golang.org/x/mod v0.29.0 // indirect
9795
golang.org/x/net v0.46.0 // indirect
9896
golang.org/x/sync v0.18.0 // indirect
99-
golang.org/x/sys v0.37.0 // indirect
100-
golang.org/x/text v0.30.0 // indirect
101-
golang.org/x/tools v0.37.0 // indirect
102-
gopkg.in/go-playground/validator.v9 v9.31.0 // indirect
97+
golang.org/x/sys v0.38.0 // indirect
98+
golang.org/x/text v0.31.0 // indirect
99+
golang.org/x/tools v0.38.0 // indirect
103100
gopkg.in/warnings.v0 v0.1.2 // indirect
104101
gopkg.in/yaml.v2 v2.4.0 // indirect
105102
gopkg.in/yaml.v3 v3.0.1 // indirect

0 commit comments

Comments
 (0)