Skip to content

Commit b3fd5c7

Browse files
Aatreyee MukherjeeAatreyee Mukherjee
authored andcommitted
added resource_block to create secrets
1 parent 0104363 commit b3fd5c7

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

ibm_catalog.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@
358358
{
359359
"key": "existing_code_engine_project_id"
360360
},
361+
{
362+
"key": "use_existing_registry_secret"
363+
},
361364
{
362365
"key": "kibana_registry_namespace_image"
363366
},

solutions/standard/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ data "http" "es_metadata" {
444444
}
445445

446446
resource "ibm_code_engine_secret" "image_registry_secret" {
447+
count = var.enable_kibana_dashboard && !var.use_existing_registry_secret ? 1 : 0
447448
name = var.kibana_image_secret
448449
project_id = var.existing_code_engine_project_id
449450
format = "registry"

solutions/standard/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ variable "admin_pass_secrets_manager_secret_name" {
346346
default = "elasticsearch-admin-password"
347347
}
348348

349+
variable "use_existing_registry_secret" {
350+
description = "Set to true to use an existing image registry secret instead of creating a new one."
351+
type = bool
352+
default = false
353+
}
354+
349355
##############################################################
350356
# Kibana Configuration
351357
##############################################################
@@ -408,6 +414,10 @@ variable "kibana_image_secret" {
408414
description = "The name of the image registry access secret."
409415
type = string
410416
default = null
417+
validation {
418+
condition = !var.enable_kibana_dashboard || var.use_existing_registry_secret || (var.kibana_image_secret != null && var.kibana_image_secret != "")
419+
error_message = "You must provide a valid secret name for Kibana image registry access."
420+
}
411421
}
412422

413423
variable "kibana_visibility" {
@@ -423,11 +433,13 @@ variable "kibana_visibility" {
423433
variable "kibana_registry_username" {
424434
description = "Username for the for the container registry."
425435
type = string
436+
default = null
426437
}
427438

428439
variable "kibana_registry_personal_access_token" {
429440
description = "Pesonal access token for the container registry."
430441
type = string
442+
default = null
431443
sensitive = true
432444
}
433445

tests/pr_test.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ func TestMain(m *testing.M) {
6161
func TestRunStandardSolutionSchematics(t *testing.T) {
6262
t.Parallel()
6363

64+
enableKibana := false
65+
6466
options := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{
6567
Testing: t,
6668
TarIncludePatterns: []string{
@@ -93,7 +95,6 @@ func TestRunStandardSolutionSchematics(t *testing.T) {
9395
},
9496
},
9597
}
96-
9798
options.TerraformVars = []testschematic.TestSchematicTerraformVar{
9899
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
99100
{Name: "access_tags", Value: permanentResources["accessTags"], DataType: "list(string)"},
@@ -109,11 +110,44 @@ func TestRunStandardSolutionSchematics(t *testing.T) {
109110
{Name: "admin_pass", Value: GetRandomAdminPassword(t), DataType: "string"},
110111
{Name: "admin_pass_secrets_manager_secret_group", Value: options.Prefix, DataType: "string"},
111112
{Name: "admin_pass_secrets_manager_secret_name", Value: options.Prefix, DataType: "string"},
112-
{Name: "enable_kibana_dashboard", Value: true, DataType: "bool"},
113+
{Name: "enable_kibana_dashboard", Value: enableKibana, DataType: "bool"},
113114
{Name: "provider_visibility", Value: "private", DataType: "string"},
114115
{Name: "prefix", Value: options.Prefix, DataType: "string"},
115116
{Name: "admin_pass", Value: GetRandomAdminPassword(t), DataType: "string"},
116117
}
118+
119+
if enableKibana {
120+
existingProjectID := os.Getenv("EXISTING_CODE_ENGINE_PROJECT_ID")
121+
kibanaImageSecret := os.Getenv("KIBANA_IMAGE_SECRET")
122+
kibanaRegistryUsername := os.Getenv("KIBANA_REGISTRY_USERNAME")
123+
kibanaRegistryToken := os.Getenv("KIBANA_REGISTRY_PERSONAL_ACCESS_TOKEN")
124+
kibanaRegistryServer := os.Getenv("KIBANA_REGISTRY_SERVER")
125+
126+
if existingProjectID == "" {
127+
t.Fatal("existing_code_engine_project_id env var must be set when enable_kibana_dashboard is true")
128+
}
129+
if kibanaImageSecret == "" {
130+
t.Fatal("kibana_image_secret env var must be set when enable_kibana_dashboard is true")
131+
}
132+
if kibanaRegistryUsername == "" {
133+
t.Fatal("kibana_registry_username env var must be set when enable_kibana_dashboard is true")
134+
}
135+
if kibanaRegistryToken == "" {
136+
t.Fatal("kibana_personal_access_token env var must be set when enable_kibana_dashboard is true")
137+
}
138+
if kibanaRegistryServer == "" {
139+
t.Fatal("kibana_registry_server env var must be set when enable_kibana_dashboard is true")
140+
}
141+
142+
options.TerraformVars = append(options.TerraformVars,
143+
testschematic.TestSchematicTerraformVar{Name: "existing_code_engine_project_id", Value: existingProjectID, DataType: "string"},
144+
testschematic.TestSchematicTerraformVar{Name: "kibana_image_secret", Value: kibanaImageSecret, DataType: "string"},
145+
testschematic.TestSchematicTerraformVar{Name: "kibana_registry_username", Value: kibanaRegistryUsername, DataType: "string"},
146+
testschematic.TestSchematicTerraformVar{Name: "kibana_registry_personal_access_token", Value: kibanaRegistryToken, DataType: "string"},
147+
testschematic.TestSchematicTerraformVar{Name: "kibana_registry_server", Value: kibanaRegistryServer, DataType: "string"},
148+
)
149+
}
150+
117151
err := options.RunSchematicTest()
118152
assert.Nil(t, err, "This should not have errored")
119153
}

0 commit comments

Comments
 (0)