Skip to content

Commit 9250fb9

Browse files
feat: Add UI regex validation to the DA (#738)
1 parent daad90b commit 9250fb9

File tree

3 files changed

+210
-16
lines changed

3 files changed

+210
-16
lines changed

ibm_catalog.json

Lines changed: 112 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,14 @@
334334
"key": "admin_pass"
335335
},
336336
{
337-
"key": "existing_secrets_manager_instance_crn"
337+
"key": "existing_secrets_manager_instance_crn",
338+
"value_constraints": [
339+
{
340+
"type": "regex",
341+
"description": "The value provided for 'existing_secrets_manager_instance_crn' is not valid.",
342+
"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}::$"
343+
}
344+
]
338345
},
339346
{
340347
"key": "existing_secrets_manager_endpoint_type",
@@ -378,10 +385,24 @@
378385
"key": "kms_encryption_enabled"
379386
},
380387
{
381-
"key": "existing_kms_instance_crn"
388+
"key": "existing_kms_instance_crn",
389+
"value_constraints": [
390+
{
391+
"type": "regex",
392+
"description": "The value provided for 'existing_kms_instance_crn' is not valid.",
393+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}(kms|hs-crypto):(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$"
394+
}
395+
]
382396
},
383397
{
384-
"key": "existing_kms_key_crn"
398+
"key": "existing_kms_key_crn",
399+
"value_constraints": [
400+
{
401+
"type": "regex",
402+
"description": "The value provided for 'existing_kms_key_crn' is not valid.",
403+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}(kms|hs-crypto):(.*:)([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}$"
404+
}
405+
]
385406
},
386407
{
387408
"key": "kms_endpoint_type",
@@ -404,10 +425,24 @@
404425
"key": "key_name"
405426
},
406427
{
407-
"key": "backup_crn"
428+
"key": "backup_crn",
429+
"value_constraints": [
430+
{
431+
"type": "regex",
432+
"description": "The value provided for 'backup_crn' is not valid.",
433+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}databases-for-postgresql:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}:backup:[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$"
434+
}
435+
]
408436
},
409437
{
410-
"key": "existing_backup_kms_key_crn"
438+
"key": "existing_backup_kms_key_crn",
439+
"value_constraints": [
440+
{
441+
"type": "regex",
442+
"description": "The value provided for 'existing_backup_kms_key_crn' is not valid.",
443+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}(kms|hs-crypto):(.*:)([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}$"
444+
}
445+
]
411446
},
412447
{
413448
"key": "use_default_backup_encryption_key"
@@ -416,10 +451,24 @@
416451
"key": "skip_postgresql_kms_auth_policy"
417452
},
418453
{
419-
"key": "existing_postgresql_instance_crn"
454+
"key": "existing_postgresql_instance_crn",
455+
"value_constraints": [
456+
{
457+
"type": "regex",
458+
"description": "The value provided for 'existing_postgresql_instance_crn' is not valid.",
459+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}databases-for-postgresql:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$"
460+
}
461+
]
420462
},
421463
{
422-
"key": "remote_leader_crn"
464+
"key": "remote_leader_crn",
465+
"value_constraints": [
466+
{
467+
"type": "regex",
468+
"description": "The value provided for 'remote_leader_crn' is not valid.",
469+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}databases-for-postgresql:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$"
470+
}
471+
]
423472
}
424473
],
425474
"terraform_version": "1.12.2",
@@ -673,7 +722,14 @@
673722
"key": "admin_pass"
674723
},
675724
{
676-
"key": "existing_secrets_manager_instance_crn"
725+
"key": "existing_secrets_manager_instance_crn",
726+
"value_constraints": [
727+
{
728+
"type": "regex",
729+
"description": "The value provided for 'existing_secrets_manager_instance_crn' is not valid.",
730+
"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}::$"
731+
}
732+
]
677733
},
678734
{
679735
"key": "skip_postgresql_secrets_manager_auth_policy"
@@ -701,10 +757,24 @@
701757
},
702758
{
703759
"key": "existing_kms_instance_crn",
704-
"required": true
760+
"required": true,
761+
"value_constraints": [
762+
{
763+
"type": "regex",
764+
"description": "The value provided for 'existing_kms_instance_crn' is not valid.",
765+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}(kms|hs-crypto):(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$"
766+
}
767+
]
705768
},
706769
{
707-
"key": "existing_kms_key_crn"
770+
"key": "existing_kms_key_crn",
771+
"value_constraints": [
772+
{
773+
"type": "regex",
774+
"description": "The value provided for 'existing_kms_key_crn' is not valid.",
775+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}(kms|hs-crypto):(.*:)([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}$"
776+
}
777+
]
708778
},
709779
{
710780
"key": "key_ring_name"
@@ -713,19 +783,47 @@
713783
"key": "key_name"
714784
},
715785
{
716-
"key": "backup_crn"
786+
"key": "backup_crn",
787+
"value_constraints": [
788+
{
789+
"type": "regex",
790+
"description": "The value provided for 'backup_crn' is not valid.",
791+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}databases-for-postgresql:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}:backup:[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$"
792+
}
793+
]
717794
},
718795
{
719-
"key": "existing_backup_kms_key_crn"
796+
"key": "existing_backup_kms_key_crn",
797+
"value_constraints": [
798+
{
799+
"type": "regex",
800+
"description": "The value provided for 'existing_backup_kms_key_crn' is not valid.",
801+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}(kms|hs-crypto):(.*:)([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}$"
802+
}
803+
]
720804
},
721805
{
722806
"key": "skip_postgresql_kms_auth_policy"
723807
},
724808
{
725-
"key": "existing_postgresql_instance_crn"
809+
"key": "existing_postgresql_instance_crn",
810+
"value_constraints": [
811+
{
812+
"type": "regex",
813+
"description": "The value provided for 'existing_postgresql_instance_crn' is not valid.",
814+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}databases-for-postgresql:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$"
815+
}
816+
]
726817
},
727818
{
728-
"key": "remote_leader_crn"
819+
"key": "remote_leader_crn",
820+
"value_constraints": [
821+
{
822+
"type": "regex",
823+
"description": "The value provided for 'remote_leader_crn' is not valid.",
824+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}databases-for-postgresql:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$"
825+
}
826+
]
729827
}
730828
],
731829
"terraform_version": "1.12.2",

solutions/fully-configurable/variables.tf

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ variable "existing_postgresql_instance_crn" {
6262
type = string
6363
default = null
6464
description = "The CRN of an existing Databases for Postgresql instance. If no value is specified, a new instance is created."
65+
66+
validation {
67+
condition = anytrue([
68+
var.existing_postgresql_instance_crn == null,
69+
can(regex("^crn:v\\d:(.*:){2}databases-for-postgresql:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$", var.existing_postgresql_instance_crn))
70+
])
71+
error_message = "The value provided for 'existing_postgresql_instance_crn' is not valid."
72+
}
6573
}
6674

6775
variable "postgresql_version" {
@@ -74,6 +82,14 @@ variable "remote_leader_crn" {
7482
type = string
7583
description = "A CRN of the leader database to make the replica(read-only) deployment. The leader database is created by a database deployment with the same service ID. A read-only replica is set up to replicate all of your data from the leader deployment to the replica deployment by using asynchronous replication. [Learn more](https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-read-only-replicas)."
7684
default = null
85+
86+
validation {
87+
condition = anytrue([
88+
var.remote_leader_crn == null,
89+
can(regex("^crn:v\\d:(.*:){2}databases-for-postgresql:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$", var.remote_leader_crn))
90+
])
91+
error_message = "The value provided for 'remote_leader_crn' is not valid."
92+
}
7793
}
7894

7995
##############################################################################
@@ -249,12 +265,28 @@ variable "existing_kms_instance_crn" {
249265
type = string
250266
description = "The CRN of a Key Protect or Hyper Protect Crypto Services instance. Required to create a new encryption key and key ring which will be used to encrypt both deployment data and backups. To use an existing key, pass values for `existing_kms_key_crn` and/or `existing_backup_kms_key_crn`. Bare in mind that backups encryption is only available in certain regions. See [Bring your own key for backups](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect&interface=ui#key-byok) and [Using the HPCS Key for Backup encryption](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hpcs#use-hpcs-backups)."
251267
default = null
268+
269+
validation {
270+
condition = anytrue([
271+
var.existing_kms_instance_crn == null,
272+
can(regex("^crn:v\\d:(.*:){2}(kms|hs-crypto):(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$", var.existing_kms_instance_crn))
273+
])
274+
error_message = "The value provided for 'existing_kms_instance_crn' is not valid."
275+
}
252276
}
253277

254278
variable "existing_kms_key_crn" {
255279
type = string
256280
description = "The CRN of a Key Protect or Hyper Protect Crypto Services encryption key to encrypt your data. By default this key is used for both deployment data and backups, but this behaviour can be altered using the optional `existing_backup_kms_key_crn` input. If no value is passed a new key will be created in the instance specified in the `existing_kms_instance_crn` input. Bare in mind that backups encryption is only available in certain regions. See [Bring your own key for backups](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect&interface=ui#key-byok) and [Using the HPCS Key for Backup encryption](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hpcs#use-hpcs-backups)."
257281
default = null
282+
283+
validation {
284+
condition = anytrue([
285+
var.existing_kms_key_crn == null,
286+
can(regex("^crn:v\\d:(.*:){2}(kms|hs-crypto):(.*:)([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_kms_key_crn))
287+
])
288+
error_message = "The value provided for 'existing_kms_key_crn’ is not valid."
289+
}
258290
}
259291

260292
variable "kms_endpoint_type" {
@@ -297,6 +329,14 @@ variable "existing_backup_kms_key_crn" {
297329
type = string
298330
description = "The CRN of a Key Protect or Hyper Protect Crypto Services encryption key that you want to use for encrypting the disk that holds deployment backups. If no value is passed, the value of `existing_kms_key_crn` is used. If no value is passed for `existing_kms_key_crn`, a new key will be created in the instance specified in the `existing_kms_instance_crn` input. Alternatively set `use_default_backup_encryption_key` to true to use the IBM Cloud Databases default encryption. Bare in mind that backups encryption is only available in certain regions. See [Bring your own key for backups](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect&interface=ui#key-byok) and [Using the HPCS Key for Backup encryption](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hpcs#use-hpcs-backups)."
299331
default = null
332+
333+
validation {
334+
condition = anytrue([
335+
var.existing_backup_kms_key_crn == null,
336+
can(regex("^crn:v\\d:(.*:){2}(kms|hs-crypto):(.*:)([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_backup_kms_key_crn))
337+
])
338+
error_message = "The value provided for 'existing_backup_kms_key_crn' is not valid."
339+
}
300340
}
301341

302342
variable "use_default_backup_encryption_key" {
@@ -313,7 +353,7 @@ variable "backup_crn" {
313353
validation {
314354
condition = anytrue([
315355
var.backup_crn == null,
316-
can(regex("^crn:.*:backup:", var.backup_crn))
356+
can(regex("^crn:v\\d:(.*:){2}databases-for-postgresql:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}:backup:[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$", var.backup_crn))
317357
])
318358
error_message = "backup_crn must be null OR starts with 'crn:' and contains ':backup:'"
319359
}
@@ -390,6 +430,14 @@ variable "existing_secrets_manager_instance_crn" {
390430
type = string
391431
default = null
392432
description = "The CRN of existing secrets manager to use to create service credential secrets for Databases for PostgreSQL instance."
433+
434+
validation {
435+
condition = anytrue([
436+
var.existing_secrets_manager_instance_crn == null,
437+
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_instance_crn))
438+
])
439+
error_message = "The value provided for 'existing_secrets_manager_instance_crn' is not valid."
440+
}
393441
}
394442

395443
variable "existing_secrets_manager_endpoint_type" {

0 commit comments

Comments
 (0)