From d048ef79cbaf872352eeeb80720f113095fb0848 Mon Sep 17 00:00:00 2001 From: raagamounica Date: Fri, 21 Nov 2025 16:52:08 +0530 Subject: [PATCH 1/4] test: updating with schematics-upgrade test --- tests/pr_test.go | 94 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 9 deletions(-) diff --git a/tests/pr_test.go b/tests/pr_test.go index c099e66c..60fd8ac8 100644 --- a/tests/pr_test.go +++ b/tests/pr_test.go @@ -77,18 +77,93 @@ func TestRunHAExample(t *testing.T) { assert.NotNil(t, output, "Expected some output") } -func TestRunHAUpgrade(t *testing.T) { +func TestFullyConfigurableSolutionInSchematics(t *testing.T) { t.Parallel() - options := setupHAOptions(t, "cts-vpn-ha-upg") - output, err := options.RunTestUpgrade() - if !options.UpgradeTestSkipped { + // ------------------------------------------------------------------------------------------------------ + // Create SLZ VPC, resource group first + // ------------------------------------------------------------------------------------------------------ + + prefix := fmt.Sprintf("cts-s-%s", strings.ToLower(random.UniqueId())) + realTerraformDir := "./resources" + tempTerraformDir, _ := files.CopyTerraformFolderToTemp(realTerraformDir, fmt.Sprintf(prefix+"-%s", strings.ToLower(random.UniqueId()))) + + // Verify ibmcloud_api_key variable is set + checkVariable := "TF_VAR_ibmcloud_api_key" + val, present := os.LookupEnv(checkVariable) + require.True(t, present, checkVariable+" environment variable not set") + require.NotEqual(t, "", val, checkVariable+" environment variable is empty") + + // Programmatically determine region to use based on availability + region, _ := testhelper.GetBestVpcRegion(val, "../common-dev-assets/common-go-assets/cloudinfo-region-vpc-gen2-prefs.yaml", "eu-de") + + logger.Log(t, "Tempdir: ", tempTerraformDir) + existingTerraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{ + TerraformDir: tempTerraformDir, + Vars: map[string]interface{}{ + "prefix": prefix, + "region": region, + "resource_tags": []string{"test-schematic"}, + }, + // Set Upgrade to true to ensure latest version of providers and modules are used by terratest. + // This is the same as setting the -upgrade=true flag with terraform. + Upgrade: true, + }) + + terraform.WorkspaceSelectOrNew(t, existingTerraformOptions, prefix) + _, existErr := terraform.InitAndApplyE(t, existingTerraformOptions) + + if existErr != nil { + assert.True(t, existErr == nil, "Init and Apply of temp resources (SLZ VPC and Secrets Manager) failed") + } else { + + options := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{ + Testing: t, + Prefix: prefix, + TarIncludePatterns: []string{ + fullyConfigurableFlavorDir + "/*.*", + "*.tf", + }, + ResourceGroup: terraform.Output(t, existingTerraformOptions, "resource_group_name"), + TemplateFolder: fullyConfigurableFlavorDir, + Tags: []string{"test-schematic"}, + DeleteWorkspaceOnFail: false, + WaitJobCompleteMinutes: 60, + Region: region, + }) + options.TerraformVars = []testschematic.TestSchematicTerraformVar{ + {Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true}, + {Name: "prefix", Value: options.Prefix, DataType: "string"}, + {Name: "existing_resource_group_name", Value: terraform.Output(t, existingTerraformOptions, "resource_group_name"), DataType: "string"}, + {Name: "existing_secrets_manager_instance_crn", Value: permanentResources["secretsManagerCRN"], DataType: "string"}, + {Name: "existing_vpc_crn", Value: terraform.Output(t, existingTerraformOptions, "management_vpc_crn"), DataType: "string"}, + {Name: "private_cert_engine_config_root_ca_common_name", Value: fmt.Sprintf("%s%s", options.Prefix, ".com"), DataType: "string"}, + {Name: "private_cert_engine_config_template_name", Value: permanentResources["privateCertTemplateName"], DataType: "string"}, + {Name: "provider_visibility", Value: "public", DataType: "string"}, + {Name: "remote_cidr", Value: "10.10.120.0/24", DataType: "string"}, + {Name: "vpn_subnet_cidr_zone_1", Value: "10.10.40.0/24", DataType: "string"}, + {Name: "vpn_subnet_cidr_zone_2", Value: "10.10.80.0/24", DataType: "string"}, + {Name: "vpn_client_access_acl_ids", Value: []string{terraform.Output(t, existingTerraformOptions, "default_network_acl_id")}, DataType: "list(string)"}, + {Name: "protocol", Value: "tcp", DataType: "string"}, + } + err := options.RunSchematicTest() assert.Nil(t, err, "This should not have errored") - assert.NotNil(t, output, "Expected some output") + } + + // Check if "DO_NOT_DESTROY_ON_FAILURE" is set + envVal, _ := os.LookupEnv("DO_NOT_DESTROY_ON_FAILURE") + // Destroy the temporary existing resources if required + if t.Failed() && strings.ToLower(envVal) == "true" { + fmt.Println("Terratest failed. Debug the test and delete resources manually.") + } else { + logger.Log(t, "START: Destroy (existing resources)") + terraform.Destroy(t, existingTerraformOptions) + terraform.WorkspaceDelete(t, existingTerraformOptions, prefix) + logger.Log(t, "END: Destroy (existing resources)") } } -func TestFullyConfigurableSolutionInSchematics(t *testing.T) { +func TestRunSchematicUpgrade(t *testing.T) { t.Parallel() // ------------------------------------------------------------------------------------------------------ @@ -157,8 +232,10 @@ func TestFullyConfigurableSolutionInSchematics(t *testing.T) { {Name: "vpn_client_access_acl_ids", Value: []string{terraform.Output(t, existingTerraformOptions, "default_network_acl_id")}, DataType: "list(string)"}, {Name: "protocol", Value: "tcp", DataType: "string"}, } - err := options.RunSchematicTest() - assert.Nil(t, err, "This should not have errored") + err := options.RunSchematicUpgradeTest() + if !options.UpgradeTestSkipped { + assert.NoError(t, err, "Upgrade test should complete without errors") + } } // Check if "DO_NOT_DESTROY_ON_FAILURE" is set @@ -173,7 +250,6 @@ func TestFullyConfigurableSolutionInSchematics(t *testing.T) { logger.Log(t, "END: Destroy (existing resources)") } } - func TestFullyConfigurableSolutionExistingResources(t *testing.T) { t.Parallel() From b8f8b0c028c9a70dd96bfe35136b15e019104348 Mon Sep 17 00:00:00 2001 From: Aatreyee Mukherjee Date: Mon, 24 Nov 2025 18:16:42 +0530 Subject: [PATCH 2/4] feat: Add next-steps URL for the DA (#528) --- solutions/fully-configurable/outputs.tf | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/solutions/fully-configurable/outputs.tf b/solutions/fully-configurable/outputs.tf index 0c719805..216b89db 100644 --- a/solutions/fully-configurable/outputs.tf +++ b/solutions/fully-configurable/outputs.tf @@ -26,3 +26,28 @@ output "vpn_id" { description = "Client to Site VPN ID" value = module.vpn.vpn_server_id } + +output "next_steps_text" { + value = "Now, you can access your VPN server." + description = "Next steps text" +} + +output "next_step_primary_label" { + value = "Go to client-to-site VPN server" + description = "Primary label" +} + +output "next_step_primary_url" { + value = "https://cloud.ibm.com/infrastructure/network/vpnServers/${module.existing_vpc_crn_parser.region}~${module.vpn.vpn_server_id}/overview" + description = "Primary URL for the Client-to-Site VPN instance" +} + +output "next_step_secondary_label" { + value = "Learn more about client-to-site VPN servers" + description = "Secondary label" +} + +output "next_step_secondary_url" { + value = "https://cloud.ibm.com/docs/vpc?topic=vpc-vpn-client-to-site-overview&interface=ui" + description = "Secondary URL" +} From 295e348df3a2af58fe5e167336983cc94e3efa7e Mon Sep 17 00:00:00 2001 From: raagamounica Date: Tue, 25 Nov 2025 18:56:15 +0530 Subject: [PATCH 3/4] test: updating with schematics-upgrade test --- tests/pr_test.go | 78 +++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/tests/pr_test.go b/tests/pr_test.go index 60fd8ac8..72c0fb69 100644 --- a/tests/pr_test.go +++ b/tests/pr_test.go @@ -163,13 +163,13 @@ func TestFullyConfigurableSolutionInSchematics(t *testing.T) { } } -func TestRunSchematicUpgrade(t *testing.T) { +// Upgrade test for "Fully configurable" DA variation in schematics +func TestFullyConfigurableSolutionUpgrade(t *testing.T) { t.Parallel() // ------------------------------------------------------------------------------------------------------ // Create SLZ VPC, resource group first // ------------------------------------------------------------------------------------------------------ - prefix := fmt.Sprintf("cts-s-%s", strings.ToLower(random.UniqueId())) realTerraformDir := "./resources" tempTerraformDir, _ := files.CopyTerraformFolderToTemp(realTerraformDir, fmt.Sprintf(prefix+"-%s", strings.ToLower(random.UniqueId()))) @@ -189,7 +189,7 @@ func TestRunSchematicUpgrade(t *testing.T) { Vars: map[string]interface{}{ "prefix": prefix, "region": region, - "resource_tags": []string{"test-schematic"}, + "resource_tags": []string{"test-schematic-upgrade"}, }, // Set Upgrade to true to ensure latest version of providers and modules are used by terratest. // This is the same as setting the -upgrade=true flag with terraform. @@ -198,49 +198,44 @@ func TestRunSchematicUpgrade(t *testing.T) { terraform.WorkspaceSelectOrNew(t, existingTerraformOptions, prefix) _, existErr := terraform.InitAndApplyE(t, existingTerraformOptions) + require.NoError(t, existErr, "Init and Apply of temp resources (SLZ VPC and Secrets Manager) failed") + + options := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{ + Testing: t, + Prefix: prefix, + TarIncludePatterns: []string{fullyConfigurableFlavorDir + "/*.*", "*.tf"}, + TemplateFolder: fullyConfigurableFlavorDir, + ResourceGroup: terraform.Output(t, existingTerraformOptions, "resource_group_name"), + CheckApplyResultForUpgrade: true, + WaitJobCompleteMinutes: 60, + Region: region, + Tags: []string{"test-schematic"}, + DeleteWorkspaceOnFail: false, + }) - if existErr != nil { - assert.True(t, existErr == nil, "Init and Apply of temp resources (SLZ VPC and Secrets Manager) failed") - } else { + options.TerraformVars = []testschematic.TestSchematicTerraformVar{ + {Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true}, + {Name: "prefix", Value: options.Prefix, DataType: "string"}, + {Name: "existing_resource_group_name", Value: terraform.Output(t, existingTerraformOptions, "resource_group_name"), DataType: "string"}, + {Name: "existing_secrets_manager_instance_crn", Value: permanentResources["secretsManagerCRN"], DataType: "string"}, + {Name: "existing_vpc_crn", Value: terraform.Output(t, existingTerraformOptions, "management_vpc_crn"), DataType: "string"}, + {Name: "private_cert_engine_config_root_ca_common_name", Value: fmt.Sprintf("%s%s", options.Prefix, ".com"), DataType: "string"}, + {Name: "private_cert_engine_config_template_name", Value: permanentResources["privateCertTemplateName"], DataType: "string"}, + {Name: "provider_visibility", Value: "public", DataType: "string"}, + {Name: "remote_cidr", Value: "10.10.120.0/24", DataType: "string"}, + {Name: "vpn_subnet_cidr_zone_1", Value: "10.10.40.0/24", DataType: "string"}, + {Name: "vpn_subnet_cidr_zone_2", Value: "10.10.80.0/24", DataType: "string"}, + {Name: "vpn_client_access_acl_ids", Value: []string{terraform.Output(t, existingTerraformOptions, "default_network_acl_id")}, DataType: "list(string)"}, + {Name: "protocol", Value: "tcp", DataType: "string"}, + } - options := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{ - Testing: t, - Prefix: prefix, - TarIncludePatterns: []string{ - fullyConfigurableFlavorDir + "/*.*", - "*.tf", - }, - ResourceGroup: terraform.Output(t, existingTerraformOptions, "resource_group_name"), - TemplateFolder: fullyConfigurableFlavorDir, - Tags: []string{"test-schematic"}, - DeleteWorkspaceOnFail: false, - WaitJobCompleteMinutes: 60, - Region: region, - }) - options.TerraformVars = []testschematic.TestSchematicTerraformVar{ - {Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true}, - {Name: "prefix", Value: options.Prefix, DataType: "string"}, - {Name: "existing_resource_group_name", Value: terraform.Output(t, existingTerraformOptions, "resource_group_name"), DataType: "string"}, - {Name: "existing_secrets_manager_instance_crn", Value: permanentResources["secretsManagerCRN"], DataType: "string"}, - {Name: "existing_vpc_crn", Value: terraform.Output(t, existingTerraformOptions, "management_vpc_crn"), DataType: "string"}, - {Name: "private_cert_engine_config_root_ca_common_name", Value: fmt.Sprintf("%s%s", options.Prefix, ".com"), DataType: "string"}, - {Name: "private_cert_engine_config_template_name", Value: permanentResources["privateCertTemplateName"], DataType: "string"}, - {Name: "provider_visibility", Value: "public", DataType: "string"}, - {Name: "remote_cidr", Value: "10.10.120.0/24", DataType: "string"}, - {Name: "vpn_subnet_cidr_zone_1", Value: "10.10.40.0/24", DataType: "string"}, - {Name: "vpn_subnet_cidr_zone_2", Value: "10.10.80.0/24", DataType: "string"}, - {Name: "vpn_client_access_acl_ids", Value: []string{terraform.Output(t, existingTerraformOptions, "default_network_acl_id")}, DataType: "list(string)"}, - {Name: "protocol", Value: "tcp", DataType: "string"}, - } - err := options.RunSchematicUpgradeTest() - if !options.UpgradeTestSkipped { - assert.NoError(t, err, "Upgrade test should complete without errors") - } + err := options.RunSchematicUpgradeTest() + if !options.UpgradeTestSkipped { + assert.NoError(t, err, "Upgrade test should complete without errors") } - // Check if "DO_NOT_DESTROY_ON_FAILURE" is set + // Clean up resources unless DO_NOT_DESTROY_ON_FAILURE is set envVal, _ := os.LookupEnv("DO_NOT_DESTROY_ON_FAILURE") - // Destroy the temporary existing resources if required if t.Failed() && strings.ToLower(envVal) == "true" { fmt.Println("Terratest failed. Debug the test and delete resources manually.") } else { @@ -250,6 +245,7 @@ func TestRunSchematicUpgrade(t *testing.T) { logger.Log(t, "END: Destroy (existing resources)") } } + func TestFullyConfigurableSolutionExistingResources(t *testing.T) { t.Parallel() From fa0c72a6a5769c31c3e28b2f0523648913d0cda5 Mon Sep 17 00:00:00 2001 From: mounicatellabati <78633728+mounicatellabati@users.noreply.github.com> Date: Tue, 25 Nov 2025 19:01:17 +0530 Subject: [PATCH 4/4] Update outputs.tf --- solutions/fully-configurable/outputs.tf | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/solutions/fully-configurable/outputs.tf b/solutions/fully-configurable/outputs.tf index 216b89db..0c719805 100644 --- a/solutions/fully-configurable/outputs.tf +++ b/solutions/fully-configurable/outputs.tf @@ -26,28 +26,3 @@ output "vpn_id" { description = "Client to Site VPN ID" value = module.vpn.vpn_server_id } - -output "next_steps_text" { - value = "Now, you can access your VPN server." - description = "Next steps text" -} - -output "next_step_primary_label" { - value = "Go to client-to-site VPN server" - description = "Primary label" -} - -output "next_step_primary_url" { - value = "https://cloud.ibm.com/infrastructure/network/vpnServers/${module.existing_vpc_crn_parser.region}~${module.vpn.vpn_server_id}/overview" - description = "Primary URL for the Client-to-Site VPN instance" -} - -output "next_step_secondary_label" { - value = "Learn more about client-to-site VPN servers" - description = "Secondary label" -} - -output "next_step_secondary_url" { - value = "https://cloud.ibm.com/docs/vpc?topic=vpc-vpn-client-to-site-overview&interface=ui" - description = "Secondary URL" -}