Skip to content

Commit 8ddf33f

Browse files
feat: Add input variable validation (#287)
1 parent 75561dc commit 8ddf33f

File tree

7 files changed

+53
-22
lines changed

7 files changed

+53
-22
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ Make sure that you have the following prerequisites:
3030
## Overview
3131
* [terraform-ibm-secrets-manager-public-cert-engine](#terraform-ibm-secrets-manager-public-cert-engine)
3232
* [Examples](./examples)
33-
* <div style="display: inline-block;"><a href="./examples/api_key_auth">Secrets Manager public certificate engine using API key authentication</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=smpce-api_key_auth-example&repository=github.com/terraform-ibm-modules/terraform-ibm-secrets-manager-public-cert-engine/tree/main/examples/api_key_auth" 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/iam_auth">Secrets Manager public certificate engine using an IBM IAM authorization policy</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=smpce-iam_auth-example&repository=github.com/terraform-ibm-modules/terraform-ibm-secrets-manager-public-cert-engine/tree/main/examples/iam_auth" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
33+
* <div style="display: inline-block;"><a href="./examples/api_key_auth">Secrets Manager public certificate engine using API key authentication</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=smpce-api_key_auth-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-secrets-manager-public-cert-engine/tree/main/examples/api_key_auth" 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/iam_auth">Secrets Manager public certificate engine using an IBM IAM authorization policy</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=smpce-iam_auth-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-secrets-manager-public-cert-engine/tree/main/examples/iam_auth" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
3535
* [Contributing](#contributing)
3636
<!-- END OVERVIEW HOOK -->
3737

ibm_catalog.json

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,14 @@
155155
},
156156
{
157157
"key": "existing_secrets_manager_crn",
158-
"required": true
158+
"required": true,
159+
"value_constraints": [
160+
{
161+
"type": "regex",
162+
"description": "The value provided for 'existing_secrets_manager_crn' is not valid.",
163+
"value": "^crn:v\\d:(.*:){2}secrets-manager:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$"
164+
}
165+
]
159166
},
160167
{
161168
"key": "prefix",
@@ -266,7 +273,14 @@
266273
"key": "ibmcloud_cis_api_key"
267274
},
268275
{
269-
"key": "internet_services_crn"
276+
"key": "internet_services_crn",
277+
"value_constraints": [
278+
{
279+
"type": "regex",
280+
"description": "The value provided for 'internet_services_crn' is not valid.",
281+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}internet-svcs:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$"
282+
}
283+
]
270284
},
271285
{
272286
"key": "internet_services_account_id"
@@ -298,7 +312,14 @@
298312
"required": true
299313
},
300314
{
301-
"key": "acme_letsencrypt_private_key_secrets_manager_secret_crn"
315+
"key": "acme_letsencrypt_private_key_secrets_manager_secret_crn",
316+
"value_constraints": [
317+
{
318+
"type": "regex",
319+
"description": "The value provided for 'acme_letsencrypt_private_key_secrets_manager_secret_crn' is not valid.",
320+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}secrets-manager:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}:secret:[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$"
321+
}
322+
]
302323
},
303324
{
304325
"key": "skip_iam_authorization_policy"

solutions/fully-configurable/variables.tf

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@ variable "provider_visibility" {
1717

1818
variable "existing_secrets_manager_crn" {
1919
type = string
20+
nullable = false
2021
description = "CRN of an existing secrets manager instance to create the secret engine in."
22+
23+
validation {
24+
condition = can(regex("^crn:v\\d:(.*:){2}secrets-manager:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$", var.existing_secrets_manager_crn))
25+
error_message = "The value provided for 'existing_secrets_manager_crn' is not valid.'"
26+
}
2127
}
2228

2329
variable "prefix" {
2430
type = string
2531
nullable = true
26-
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: prod-us-south. [Learn more](https://terraform-ibm-modules.github.io/documentation/#/prefix.md)."
32+
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)."
2733

2834
validation {
2935
# - null and empty string is allowed
@@ -64,6 +70,15 @@ variable "internet_services_crn" {
6470
type = string
6571
description = "The CRN of the Internet Service instance to authorize Secrets Manager against. For creating a public certificate, if using Cloud Internet Service for DNS then `internet_service_crn` is a required input. [Learn more](https://cloud.ibm.com/docs/secrets-manager?topic=secrets-manager-secrets-manager-cli#secrets-manager-configurations-cli)."
6672
default = null
73+
74+
validation {
75+
condition = anytrue([
76+
can(regex("^crn:v\\d:(.*:){2}internet-svcs:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$", var.internet_services_crn)),
77+
var.internet_services_crn == null,
78+
])
79+
error_message = "The value provided for 'internet_services_crn' is not valid."
80+
81+
}
6782
}
6883

6984
variable "internet_services_account_id" {
@@ -131,4 +146,12 @@ variable "acme_letsencrypt_private_key_secrets_manager_secret_crn" {
131146
)
132147
error_message = "If `acme_letsencrypt_private_key` is not set, you must provide a value for `acme_letsencrypt_private_key_secrets_manager_secret_crn`."
133148
}
149+
validation {
150+
condition = anytrue([
151+
can(regex("^crn:v\\d:(.*:){2}secrets-manager:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}:secret:[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$", var.acme_letsencrypt_private_key_secrets_manager_secret_crn)),
152+
var.acme_letsencrypt_private_key_secrets_manager_secret_crn == null,
153+
])
154+
error_message = "The value provided for 'acme_letsencrypt_private_key_secrets_manager_secret_crn' is not valid."
155+
156+
}
134157
}

tests/go.mod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,16 @@ require (
1111
)
1212

1313
require (
14-
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
1514
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
1615
go.yaml.in/yaml/v2 v2.4.2 // indirect
17-
gopkg.in/go-playground/validator.v9 v9.31.0 // indirect
1816
)
1917

2018
require (
2119
dario.cat/mergo v1.0.0 // indirect
2220
github.com/IBM-Cloud/bluemix-go v0.0.0-20240719075425-078fcb3a55be // indirect
2321
github.com/IBM-Cloud/power-go-client v1.13.0 // indirect
2422
github.com/IBM/cloud-databases-go-sdk v0.8.1 // indirect
25-
github.com/IBM/go-sdk-core v1.1.0
26-
github.com/IBM/go-sdk-core/v5 v5.21.0 // indirect
23+
github.com/IBM/go-sdk-core/v5 v5.21.0
2724
github.com/IBM/platform-services-go-sdk v0.90.0 // indirect
2825
github.com/IBM/project-go-sdk v0.3.9 // indirect
2926
github.com/IBM/schematics-go-sdk v0.4.0 // indirect

tests/go.sum

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ github.com/IBM-Cloud/power-go-client v1.13.0 h1:TqxPlkJe0VkNdV9hYOD5NRepxEFhhyKX
66
github.com/IBM-Cloud/power-go-client v1.13.0/go.mod h1:SpTK1ttW8bfMNUVQS8qOEuWn2KOkzaCLyzfze8MG1JE=
77
github.com/IBM/cloud-databases-go-sdk v0.8.1 h1:ULQ5L8V/9z79/qS185LqbIK2LD4kMtk3Hdhp4lFMVcw=
88
github.com/IBM/cloud-databases-go-sdk v0.8.1/go.mod h1:JYucI1PdwqbAd8XGdDAchxzxRP7bxOh1zUnseovHKsc=
9-
github.com/IBM/go-sdk-core v1.1.0 h1:pV73lZqr9r1xKb3h08c1uNG3AphwoV5KzUzhS+pfEqY=
10-
github.com/IBM/go-sdk-core v1.1.0/go.mod h1:2pcx9YWsIsZ3I7kH+1amiAkXvLTZtAq9kbxsfXilSoY=
119
github.com/IBM/go-sdk-core/v5 v5.9.2/go.mod h1:YlOwV9LeuclmT/qi/LAK2AsobbAP42veV0j68/rlZsE=
1210
github.com/IBM/go-sdk-core/v5 v5.21.0 h1:DUnYhvC4SoC8T84rx5omnhY3+xcQg/Whyoa3mDPIMkk=
1311
github.com/IBM/go-sdk-core/v5 v5.21.0/go.mod h1:Q3BYO6iDA2zweQPDGbNTtqft5tDcEpm6RTuqMlPcvbw=
@@ -50,8 +48,6 @@ github.com/cyphar/filepath-securejoin v0.4.1/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGL
5048
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5149
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5250
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
53-
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
54-
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
5551
github.com/elazarl/goproxy v1.7.2 h1:Y2o6urb7Eule09PjlhQRGNsqRfPmYI3KKQLFpCAV3+o=
5652
github.com/elazarl/goproxy v1.7.2/go.mod h1:82vkLNir0ALaW14Rc399OTTjyNREgmdL2cVoIbS6XaE=
5753
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
@@ -110,11 +106,9 @@ github.com/go-openapi/validate v0.24.0 h1:LdfDKwNbpB6Vn40xhTdNZAnfLECL81w+VX3Bum
110106
github.com/go-openapi/validate v0.24.0/go.mod h1:iyeX1sEufmv3nPbBdX3ieNviWnOZaJ1+zquzJEf2BAQ=
111107
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
112108
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
113-
github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=
114109
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
115110
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
116111
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
117-
github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=
118112
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
119113
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
120114
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
@@ -201,7 +195,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
201195
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
202196
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
203197
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
204-
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
205198
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
206199
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
207200
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
@@ -519,10 +512,7 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8
519512
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
520513
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
521514
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
522-
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
523515
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
524-
gopkg.in/go-playground/validator.v9 v9.30.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
525-
gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M=
526516
gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
527517
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
528518
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=

tests/pr_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os"
77
"testing"
88

9-
"github.com/IBM/go-sdk-core/core"
9+
"github.com/IBM/go-sdk-core/v5/core"
1010
"github.com/gruntwork-io/terratest/modules/logger"
1111
"github.com/gruntwork-io/terratest/modules/terraform"
1212
"github.com/stretchr/testify/assert"

0 commit comments

Comments
 (0)