Skip to content

Commit 6611fb5

Browse files
arya-girish-kArya Girish Kshemau
authored
feat: Add UI regex validation to the DA (#349)
* feat: Add UI regex-validation * feat: Added regex validation for remote_leader_crn * feat: updated validation * updated CRN pattern --------- Co-authored-by: Arya Girish K <[email protected]> Co-authored-by: shemau <[email protected]>
1 parent 699709b commit 6611fb5

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
@@ -325,7 +325,14 @@
325325
"key": "admin_pass"
326326
},
327327
{
328-
"key": "existing_secrets_manager_instance_crn"
328+
"key": "existing_secrets_manager_instance_crn",
329+
"value_constraints": [
330+
{
331+
"type": "regex",
332+
"description": "The value provided for 'existing_secrets_manager_instance_crn' is not valid.",
333+
"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}::$"
334+
}
335+
]
329336
},
330337
{
331338
"key": "existing_secrets_manager_endpoint_type",
@@ -369,10 +376,24 @@
369376
"key": "kms_encryption_enabled"
370377
},
371378
{
372-
"key": "existing_kms_instance_crn"
379+
"key": "existing_kms_instance_crn",
380+
"value_constraints": [
381+
{
382+
"type": "regex",
383+
"description": "The value provided for 'existing_kms_instance_crn' is not valid.",
384+
"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}::$"
385+
}
386+
]
373387
},
374388
{
375-
"key": "existing_kms_key_crn"
389+
"key": "existing_kms_key_crn",
390+
"value_constraints": [
391+
{
392+
"type": "regex",
393+
"description": "The value provided for 'existing_kms_key_crn' is not valid.",
394+
"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}$"
395+
}
396+
]
376397
},
377398
{
378399
"key": "kms_endpoint_type",
@@ -395,10 +416,24 @@
395416
"key": "key_name"
396417
},
397418
{
398-
"key": "backup_crn"
419+
"key": "backup_crn",
420+
"value_constraints": [
421+
{
422+
"type": "regex",
423+
"description": "The value provided for 'backup_crn' is not valid.",
424+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}databases-for-mysql:(.*:)([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}$"
425+
}
426+
]
399427
},
400428
{
401-
"key": "existing_backup_kms_key_crn"
429+
"key": "existing_backup_kms_key_crn",
430+
"value_constraints": [
431+
{
432+
"type": "regex",
433+
"description": "The value provided for 'existing_backup_kms_key_crn' is not valid.",
434+
"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}$"
435+
}
436+
]
402437
},
403438
{
404439
"key": "use_default_backup_encryption_key"
@@ -407,10 +442,24 @@
407442
"key": "skip_mysql_kms_auth_policy"
408443
},
409444
{
410-
"key": "existing_mysql_instance_crn"
445+
"key": "existing_mysql_instance_crn",
446+
"value_constraints": [
447+
{
448+
"type": "regex",
449+
"description": "The value provided for 'existing_mysql_instance_crn' is not valid.",
450+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}databases-for-mysql:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$"
451+
}
452+
]
411453
},
412454
{
413-
"key": "remote_leader_crn"
455+
"key": "remote_leader_crn",
456+
"value_constraints": [
457+
{
458+
"type": "regex",
459+
"description": "The value provided for 'remote_leader_crn' is not valid.",
460+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}databases-for-mysql:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$"
461+
}
462+
]
414463
}
415464
],
416465
"terraform_version": "1.12.2",
@@ -656,7 +705,14 @@
656705
"key": "admin_pass"
657706
},
658707
{
659-
"key": "existing_secrets_manager_instance_crn"
708+
"key": "existing_secrets_manager_instance_crn",
709+
"value_constraints": [
710+
{
711+
"type": "regex",
712+
"description": "The value provided for 'existing_secrets_manager_instance_crn' is not valid.",
713+
"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}::$"
714+
}
715+
]
660716
},
661717
{
662718
"key": "skip_mysql_secrets_manager_auth_policy"
@@ -684,10 +740,24 @@
684740
},
685741
{
686742
"key": "existing_kms_instance_crn",
687-
"required": true
743+
"required": true,
744+
"value_constraints": [
745+
{
746+
"type": "regex",
747+
"description": "The value provided for 'existing_kms_instance_crn' is not valid.",
748+
"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}::$"
749+
}
750+
]
688751
},
689752
{
690-
"key": "existing_kms_key_crn"
753+
"key": "existing_kms_key_crn",
754+
"value_constraints": [
755+
{
756+
"type": "regex",
757+
"description": "The value provided for 'existing_kms_key_crn' is not valid.",
758+
"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}$"
759+
}
760+
]
691761
},
692762
{
693763
"key": "key_ring_name"
@@ -696,19 +766,47 @@
696766
"key": "key_name"
697767
},
698768
{
699-
"key": "backup_crn"
769+
"key": "backup_crn",
770+
"value_constraints": [
771+
{
772+
"type": "regex",
773+
"description": "The value provided for 'backup_crn' is not valid.",
774+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}databases-for-mysql:(.*:)([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}$"
775+
}
776+
]
700777
},
701778
{
702-
"key": "existing_backup_kms_key_crn"
779+
"key": "existing_backup_kms_key_crn",
780+
"value_constraints": [
781+
{
782+
"type": "regex",
783+
"description": "The value provided for 'existing_backup_kms_key_crn' is not valid.",
784+
"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}$"
785+
}
786+
]
703787
},
704788
{
705789
"key": "skip_mysql_kms_auth_policy"
706790
},
707791
{
708-
"key": "existing_mysql_instance_crn"
792+
"key": "existing_mysql_instance_crn",
793+
"value_constraints": [
794+
{
795+
"type": "regex",
796+
"description": "The value provided for 'existing_mysql_instance_crn' is not valid.",
797+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}databases-for-mysql:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$"
798+
}
799+
]
709800
},
710801
{
711-
"key": "remote_leader_crn"
802+
"key": "remote_leader_crn",
803+
"value_constraints": [
804+
{
805+
"type": "regex",
806+
"description": "The value provided for 'remote_leader_crn' is not valid.",
807+
"value": "^__NULL__$|^crn:v\\d:(.*:){2}databases-for-mysql:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$"
808+
}
809+
]
712810
}
713811
],
714812
"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_mysql_instance_crn" {
6262
type = string
6363
default = null
6464
description = "The CRN of an existing Databases for MySql instance. If no value is specified, a new instance is created."
65+
66+
validation {
67+
condition = anytrue([
68+
var.existing_mysql_instance_crn == null,
69+
can(regex("^crn:v\\d:(.*:){2}databases-for-mysql:(.*:)([aos]\\/[\\w_\\-]+):[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}::$", var.existing_mysql_instance_crn))
70+
])
71+
error_message = "The value provided for 'existing_mysql_instance_crn' is not valid."
72+
}
6573
}
6674

6775
variable "mysql_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-mysql?topic=databases-for-mysql-read-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-mysql:(.*:)([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
##############################################################################
@@ -251,12 +267,28 @@ variable "existing_kms_instance_crn" {
251267
type = string
252268
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)."
253269
default = null
270+
271+
validation {
272+
condition = anytrue([
273+
var.existing_kms_instance_crn == null,
274+
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))
275+
])
276+
error_message = "The value provided for 'existing_kms_instance_crn' is not valid."
277+
}
254278
}
255279

256280
variable "existing_kms_key_crn" {
257281
type = string
258282
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)."
259283
default = null
284+
285+
validation {
286+
condition = anytrue([
287+
var.existing_kms_key_crn == null,
288+
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))
289+
])
290+
error_message = "The value provided for 'existing_kms_key_crn’ is not valid."
291+
}
260292
}
261293

262294
variable "kms_endpoint_type" {
@@ -299,6 +331,14 @@ variable "existing_backup_kms_key_crn" {
299331
type = string
300332
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)."
301333
default = null
334+
335+
validation {
336+
condition = anytrue([
337+
var.existing_backup_kms_key_crn == null,
338+
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))
339+
])
340+
error_message = "The value provided for 'existing_backup_kms_key_crn' is not valid."
341+
}
302342
}
303343

304344
variable "use_default_backup_encryption_key" {
@@ -315,7 +355,7 @@ variable "backup_crn" {
315355
validation {
316356
condition = anytrue([
317357
var.backup_crn == null,
318-
can(regex("^crn:.*:backup:", var.backup_crn))
358+
can(regex("^crn:v\\d:(.*:){2}databases-for-mysql:(.*:)([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))
319359
])
320360
error_message = "backup_crn must be null OR starts with 'crn:' and contains ':backup:'"
321361
}
@@ -392,6 +432,14 @@ variable "existing_secrets_manager_instance_crn" {
392432
type = string
393433
default = null
394434
description = "The CRN of existing secrets manager to use to create service credential secrets for Databases for MySQL instance."
435+
436+
validation {
437+
condition = anytrue([
438+
var.existing_secrets_manager_instance_crn == null,
439+
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))
440+
])
441+
error_message = "The value provided for 'existing_secrets_manager_instance_crn' is not valid."
442+
}
395443
}
396444

397445
variable "existing_secrets_manager_endpoint_type" {

0 commit comments

Comments
 (0)