Skip to content

Commit 90db5b0

Browse files
committed
added prefix variable
1 parent d25728c commit 90db5b0

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

ibm_catalog.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,17 @@
218218
"key": "ibmcloud_api_key",
219219
"required": true
220220
},
221+
{
222+
"key": "prefix",
223+
"required": true,
224+
"value_constraints": [
225+
{
226+
"type": "regex",
227+
"description": "Prefix must begin with a lowercase letter and may contain only lowercase letters, digits, and hyphens '-'. It must not end with a hyphen('-'), and cannot contain consecutive hyphens ('--'). It should not exceed 16 characters",
228+
"value": "^$|^__NULL__$|^[a-z](?!.*--)(?:[a-z0-9-]{0,14}[a-z0-9])?$"
229+
}
230+
]
231+
},
221232
{
222233
"display_name": "cluster",
223234
"key": "cluster_id",
@@ -507,14 +518,6 @@
507518
{
508519
"key": "enable_universal_ebpf"
509520
},
510-
{
511-
"key": "prefix",
512-
"type": "string",
513-
"required": true,
514-
"virtual": true,
515-
"default_value": "test",
516-
"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)."
517-
},
518521
{
519522
"key": "cluster_name",
520523
"type": "string",

solutions/fully-configurable/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ data "ibm_container_cluster_config" "cluster_config" {
1010
}
1111

1212
locals {
13+
prefix = var.prefix != null ? trimspace(var.prefix) != "" ? "${var.prefix}-" : "" : ""
1314
create_access_key = ((var.access_key != null && var.access_key != "") || (var.existing_access_key_secret_name != null && var.existing_access_key_secret_name != "")) ? 0 : 1
1415
}
1516

@@ -22,7 +23,7 @@ module "instance_crn_parser" {
2223

2324
resource "ibm_resource_key" "key" {
2425
count = local.create_access_key
25-
name = "key-${var.cluster_id}"
26+
name = "${local.prefix}-key"
2627
resource_instance_id = module.instance_crn_parser.service_instance
2728
role = "Manager"
2829
}

solutions/fully-configurable/variables.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,33 @@ variable "ibmcloud_api_key" {
88
sensitive = true
99
}
1010

11+
variable "prefix" {
12+
type = string
13+
nullable = true
14+
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)."
15+
16+
validation {
17+
# - null and empty string is allowed
18+
# - Must not contain consecutive hyphens (--): length(regexall("--", var.prefix)) == 0
19+
# - Starts with a lowercase letter: [a-z]
20+
# - Contains only lowercase letters (a–z), digits (0–9), and hyphens (-)
21+
# - Must not end with a hyphen (-): [a-z0-9]
22+
condition = (var.prefix == null || var.prefix == "" ? true :
23+
alltrue([
24+
can(regex("^[a-z][-a-z0-9]*[a-z0-9]$", var.prefix)),
25+
length(regexall("--", var.prefix)) == 0
26+
])
27+
)
28+
error_message = "Prefix must begin with a lowercase letter and may contain only lowercase letters, digits, and hyphens '-'. It must not end with a hyphen('-'), and cannot contain consecutive hyphens ('--')."
29+
}
30+
31+
validation {
32+
# must not exceed 16 characters in length
33+
condition = var.prefix == null || var.prefix == "" ? true : length(var.prefix) <= 16
34+
error_message = "Prefix must not exceed 16 characters."
35+
}
36+
}
37+
1138
variable "cluster_id" {
1239
type = string
1340
description = "The ID of the cluster you wish to deploy the agent in."

tests/pr_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestFullyConfigurableSolution(t *testing.T) {
9696

9797
options := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{
9898
Testing: t,
99-
Prefix: "monitoring-agent",
99+
Prefix: "mon-agent",
100100
TarIncludePatterns: []string{
101101
"*.tf",
102102
"kubeconfig/*.*",
@@ -116,6 +116,7 @@ func TestFullyConfigurableSolution(t *testing.T) {
116116
})
117117
options.TerraformVars = []testschematic.TestSchematicTerraformVar{
118118
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
119+
{Name: "prefix", Value: options.Prefix, DataType: "string"},
119120
{Name: "cluster_id", Value: terraform.Output(t, existingTerraformOptions, "cluster_id"), DataType: "string"},
120121
{Name: "cluster_resource_group_id", Value: terraform.Output(t, existingTerraformOptions, "cluster_resource_group_id"), DataType: "string"},
121122
{Name: "instance_crn", Value: terraform.Output(t, existingTerraformOptions, "instance_crn"), DataType: "string", Secure: true},
@@ -180,7 +181,7 @@ func TestFullyConfigurableUpgradeSolution(t *testing.T) {
180181

181182
options := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{
182183
Testing: t,
183-
Prefix: "monitoring-agent",
184+
Prefix: "mon-agent",
184185
TarIncludePatterns: []string{
185186
"*.tf",
186187
"kubeconfig/*.*",
@@ -201,6 +202,7 @@ func TestFullyConfigurableUpgradeSolution(t *testing.T) {
201202

202203
options.TerraformVars = []testschematic.TestSchematicTerraformVar{
203204
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
205+
{Name: "prefix", Value: options.Prefix, DataType: "string"},
204206
{Name: "cluster_id", Value: terraform.Output(t, existingTerraformOptions, "cluster_id"), DataType: "string"},
205207
{Name: "cluster_resource_group_id", Value: terraform.Output(t, existingTerraformOptions, "cluster_resource_group_id"), DataType: "string"},
206208
{Name: "instance_crn", Value: terraform.Output(t, existingTerraformOptions, "instance_crn"), DataType: "string", Secure: true},

0 commit comments

Comments
 (0)