diff --git a/solutions/agents/variables.tf b/solutions/agents/variables.tf index dd6db963..37c2f2c0 100644 --- a/solutions/agents/variables.tf +++ b/solutions/agents/variables.tf @@ -8,6 +8,16 @@ variable "prefix" { type = string description = "The prefix for resources created by this solution." default = null + validation { + condition = anytrue([ + var.prefix == null, + alltrue([ + can(regex("^([a-z]|[a-z][-a-z0-9]{0,14}[a-z0-9])$", var.prefix)), + length(regexall("^.*--.*", var.prefix)) == 0 + ]) + ]) + error_message = "Prefix must begin with a lowercase letter, contain only lowercase letters, numbers, and - characters. Prefixes must end with a lowercase letter or number and be 16 or fewer characters." + } } variable "provider_visibility" { description = "Set the visibility value for the IBM terraform provider. Supported values are `public`, `private`, `public-and-private`. [Learn more](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/guides/custom-service-endpoints)." diff --git a/solutions/instances/variables.tf b/solutions/instances/variables.tf index 99ac98c6..05acbb87 100644 --- a/solutions/instances/variables.tf +++ b/solutions/instances/variables.tf @@ -49,6 +49,16 @@ variable "prefix" { type = string description = "The prefix to add to all resources that this solution creates." default = null + validation { + condition = anytrue([ + var.prefix == null, + alltrue([ + can(regex("^([a-z]|[a-z][-a-z0-9]{0,14}[a-z0-9])$", var.prefix)), + length(regexall("^.*--.*", var.prefix)) == 0 + ]) + ]) + error_message = "Prefix must begin with a lowercase letter, contain only lowercase letters, numbers, and - characters. Prefixes must end with a lowercase letter or number and be 16 or fewer characters." + } } variable "provider_visibility" { description = "Set the visibility value for the IBM terraform provider. Supported values are `public`, `private`, `public-and-private`. [Learn more](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/guides/custom-service-endpoints)." diff --git a/tests/pr_test.go b/tests/pr_test.go index 022415f3..47ebdea8 100644 --- a/tests/pr_test.go +++ b/tests/pr_test.go @@ -61,7 +61,7 @@ func TestInstancesInSchematics(t *testing.T) { options := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{ Testing: t, - Prefix: "instance-da", + Prefix: "inst-da", TarIncludePatterns: []string{ "*.tf", solutionInstanceDADir + "/*.tf",