Skip to content

Commit c294fda

Browse files
Jordan-Williams2Jordan-Williams2
authored andcommitted
fix: schematics test issues
1 parent 2298909 commit c294fda

File tree

2 files changed

+18
-184
lines changed

2 files changed

+18
-184
lines changed

patterns/vsi/override.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
{
4848
"buckets": [
4949
{
50-
"endpoint_type": "public",
50+
"endpoint_type": "direct",
5151
"force_delete": true,
5252
"kms_key": "slz-slz-key",
5353
"name": "management-bucket",
@@ -69,7 +69,7 @@
6969
}
7070
},
7171
{
72-
"endpoint_type": "public",
72+
"endpoint_type": "direct",
7373
"force_delete": true,
7474
"kms_key": "slz-slz-key",
7575
"name": "workload-bucket",

tests/pr_test.go

Lines changed: 16 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package test
22

33
import (
4-
"encoding/json"
54
"fmt"
65
"io/fs"
76
"log"
@@ -10,9 +9,7 @@ import (
109
"strings"
1110
"testing"
1211

13-
"github.com/gruntwork-io/terratest/modules/files"
1412
"github.com/gruntwork-io/terratest/modules/logger"
15-
"github.com/gruntwork-io/terratest/modules/random"
1613
"github.com/gruntwork-io/terratest/modules/terraform"
1714
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/cloudinfo"
1815
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/common"
@@ -166,6 +163,9 @@ func TestRunQuickStartPattern(t *testing.T) {
166163

167164
func TestRunUpgradeQuickStartPattern(t *testing.T) {
168165
t.Parallel()
166+
if enableSchematicsTests {
167+
t.Skip("Skipping terratest for Quickstart Pattern upgrade, running Schematics test instead")
168+
}
169169

170170
options := setupOptionsQuickStartPattern(t, "vsi-qs-u", quickStartPatternTerraformDir)
171171

@@ -206,6 +206,9 @@ func TestRunROKSQuickStartPattern(t *testing.T) {
206206

207207
func TestRunUpgradeROKSQuickStartPattern(t *testing.T) {
208208
t.Parallel()
209+
if enableSchematicsTests {
210+
t.Skip("Skipping terratest for ROKS Quickstart Pattern upgrade, running Schematics test instead")
211+
}
209212

210213
options := setupOptionsROKSQuickStartPattern(t, "rokqsu", roksQuickstartPatternTerraformDir)
211214

@@ -255,6 +258,9 @@ func TestRunRoksPattern(t *testing.T) {
255258

256259
func TestRunUpgradeRoksPattern(t *testing.T) {
257260
t.Parallel()
261+
if enableSchematicsTests {
262+
t.Skip("Skipping terratest for ROKS Pattern upgrade, running Schematics test instead")
263+
}
258264

259265
options := setupOptionsRoksPattern(t, "ocp-u")
260266

@@ -304,6 +310,9 @@ func TestRunVSIPattern(t *testing.T) {
304310

305311
func TestRunUpgradeVsiPattern(t *testing.T) {
306312
t.Parallel()
313+
if enableSchematicsTests {
314+
t.Skip("Skipping terratest for VSI Pattern upgrade, running Schematics test instead")
315+
}
307316

308317
options := setupOptionsVsiPattern(t, "vsi-u")
309318

@@ -350,6 +359,9 @@ func TestRunVpcPattern(t *testing.T) {
350359

351360
func TestRunUpgradeVpcPattern(t *testing.T) {
352361
t.Parallel()
362+
if enableSchematicsTests {
363+
t.Skip("Skipping terratest for VPC Pattern upgrade, running Schematics test instead")
364+
}
353365

354366
options := setupOptionsVpcPattern(t, "vpc-ug")
355367

@@ -428,69 +440,12 @@ func setupOptionsSchematics(t *testing.T, prefix string, dir string) *testschema
428440
return options
429441
}
430442

431-
func setupOptionsVsiExtention(t *testing.T, prefix string, region string, existingTerraformOptions *terraform.Options) *testhelper.TestOptions {
432-
433-
sshPublicKey := sshPublicKey(t)
434-
outputVpcJson := terraform.OutputJson(t, existingTerraformOptions, "vpc_data")
435-
436-
var managementVpcID string
437-
var vpcs []struct {
438-
VpcID string `json:"vpc_id"`
439-
VpcName string `json:"vpc_name"`
440-
}
441-
// Unmarshal the JSON data into the struct
442-
if err := json.Unmarshal([]byte(outputVpcJson), &vpcs); err != nil {
443-
fmt.Println(err)
444-
return nil
445-
}
446-
// Loop through the vpcs and find the vpc_id when vpc_name is "<prefix>-management"
447-
for _, vpc := range vpcs {
448-
if vpc.VpcName == fmt.Sprintf("%s-management", prefix) {
449-
managementVpcID = vpc.VpcID
450-
}
451-
}
452-
453-
outputKeysJson := terraform.OutputJson(t, existingTerraformOptions, "key_map")
454-
var keyID string
455-
var keys map[string]map[string]string
456-
// Unmarshal the JSON data into the map
457-
if err := json.Unmarshal([]byte(outputKeysJson), &keys); err != nil {
458-
fmt.Println(err)
459-
return nil
460-
}
461-
462-
// Extract the key_id for the name "test-vsi-volume-key."
463-
if keyData, ok := keys[fmt.Sprintf("%s-vsi-volume-key", prefix)]; ok {
464-
keyID = keyData["crn"]
465-
} else {
466-
fmt.Println("Name 'test-vsi-volume-key' not found in the JSON data.")
467-
}
468-
// ------------------------------------------------------------------------------------
469-
// Deploy landing-zone extension
470-
// ------------------------------------------------------------------------------------
471-
options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
472-
Testing: t,
473-
TerraformDir: "patterns/vsi-extension",
474-
// Do not hard fail the test if the implicit destroy steps fail to allow a full destroy of resource to occur
475-
ImplicitRequired: false,
476-
TerraformVars: map[string]interface{}{
477-
"prefix": prefix,
478-
"region": region,
479-
"boot_volume_encryption_key": keyID,
480-
"vpc_id": managementVpcID,
481-
"ssh_public_key": sshPublicKey,
482-
},
483-
})
484-
485-
return options
486-
}
487-
488443
/***************************************************************************
489444
SCHEMATICS TESTS
490445
These schematics tests will only be run if the "RUN_SCHEMATICS_TESTS"
491446
environment variable is set to "true" or "yes".
492447
If not set, the normal terratest will be run for the patterns.
493-
****************************************************************************/
448+
***************************************************************************/
494449

495450
func TestRunVSIQuickStartPatternSchematics(t *testing.T) {
496451
t.Parallel()
@@ -598,127 +553,6 @@ func TestRunVPCPatternSchematics(t *testing.T) {
598553
assert.NoError(t, err, "Schematic Test had unexpected error")
599554
}
600555

601-
func TestRunVsiExtention(t *testing.T) {
602-
t.Parallel()
603-
604-
// ------------------------------------------------------------------------------------
605-
// Deploy SLZ VPC first since it is needed for the landing-zone extension input
606-
// ------------------------------------------------------------------------------------
607-
608-
prefix := fmt.Sprintf("vsi-slz-%s", strings.ToLower(random.UniqueId()))
609-
realTerraformDir := ".."
610-
tempTerraformDir, _ := files.CopyTerraformFolderToTemp(realTerraformDir, fmt.Sprintf(prefix+"-%s", strings.ToLower(random.UniqueId())))
611-
vpcTerraformDir := realTerraformDir + "/patterns/vpc"
612-
tags := common.GetTagsFromTravis()
613-
614-
// Verify ibmcloud_api_key variable is set
615-
checkVariable := "TF_VAR_ibmcloud_api_key"
616-
val, present := os.LookupEnv(checkVariable)
617-
require.True(t, present, checkVariable+" environment variable not set")
618-
require.NotEqual(t, "", val, checkVariable+" environment variable is empty")
619-
620-
// Programmatically determine region to use based on availability
621-
region, _ := testhelper.GetBestVpcRegion(val, "../common-dev-assets/common-go-assets/cloudinfo-region-vpc-gen2-prefs.yaml", "eu-de")
622-
623-
logger.Log(t, "Tempdir: ", tempTerraformDir)
624-
existingTerraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
625-
TerraformDir: vpcTerraformDir,
626-
Vars: map[string]interface{}{
627-
"prefix": prefix,
628-
"region": region,
629-
"tags": tags,
630-
"enable_transit_gateway": false,
631-
},
632-
// Set Upgrade to true to ensure latest version of providers and modules are used by terratest.
633-
// This is the same as setting the -upgrade=true flag with terraform.
634-
Upgrade: true,
635-
})
636-
637-
terraform.WorkspaceSelectOrNew(t, existingTerraformOptions, prefix)
638-
_, existErr := terraform.InitAndApplyE(t, existingTerraformOptions)
639-
if existErr != nil {
640-
assert.True(t, existErr == nil, "Init and Apply of temp existing resource failed")
641-
} else {
642-
options := setupOptionsVsiExtention(t, prefix, region, existingTerraformOptions)
643-
output, err := options.RunTestConsistency()
644-
assert.Nil(t, err, "This should not have errored")
645-
assert.NotNil(t, output, "Expected some output")
646-
}
647-
648-
// Check if "DO_NOT_DESTROY_ON_FAILURE" is set
649-
envVal, _ := os.LookupEnv("DO_NOT_DESTROY_ON_FAILURE")
650-
// Destroy the temporary existing resources if required
651-
if t.Failed() && strings.ToLower(envVal) == "true" {
652-
fmt.Println("Terratest failed. Debug the test and delete resources manually.")
653-
} else {
654-
logger.Log(t, "START: Destroy (existing resources)")
655-
// ignore resource groups when destroying
656-
terraform.RunTerraformCommand(t, existingTerraformOptions, "state", "rm", "module.vpc_landing_zone.module.landing_zone.ibm_resource_group.resource_groups")
657-
terraform.Destroy(t, existingTerraformOptions)
658-
terraform.WorkspaceDelete(t, existingTerraformOptions, prefix)
659-
logger.Log(t, "END: Destroy (existing resources)")
660-
}
661-
}
662-
663-
func TestRunUpgradeVsiExtention(t *testing.T) {
664-
// ------------------------------------------------------------------------------------
665-
// Deploy SLZ VPC first since it is needed for the landing-zone extension input
666-
// ------------------------------------------------------------------------------------
667-
668-
prefix := fmt.Sprintf("vsi-upg-%s", strings.ToLower(random.UniqueId()))
669-
realTerraformDir := ".."
670-
tempTerraformDir, _ := files.CopyTerraformFolderToTemp(realTerraformDir, fmt.Sprintf(prefix+"-%s", strings.ToLower(random.UniqueId())))
671-
vpcTerraformDir := realTerraformDir + "/patterns/vpc"
672-
tags := common.GetTagsFromTravis()
673-
674-
// Verify ibmcloud_api_key variable is set
675-
checkVariable := "TF_VAR_ibmcloud_api_key"
676-
val, present := os.LookupEnv(checkVariable)
677-
require.True(t, present, checkVariable+" environment variable not set")
678-
require.NotEqual(t, "", val, checkVariable+" environment variable is empty")
679-
680-
// Programmatically determine region to use based on availability
681-
region, _ := testhelper.GetBestVpcRegion(val, "../common-dev-assets/common-go-assets/cloudinfo-region-vpc-gen2-prefs.yaml", "eu-de")
682-
683-
logger.Log(t, "Tempdir: ", tempTerraformDir)
684-
existingTerraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
685-
TerraformDir: vpcTerraformDir,
686-
Vars: map[string]interface{}{
687-
"prefix": prefix,
688-
"region": region,
689-
"tags": tags,
690-
},
691-
// Set Upgrade to true to ensure latest version of providers and modules are used by terratest.
692-
// This is the same as setting the -upgrade=true flag with terraform.
693-
Upgrade: true,
694-
})
695-
696-
terraform.WorkspaceSelectOrNew(t, existingTerraformOptions, prefix)
697-
_, existErr := terraform.InitAndApplyE(t, existingTerraformOptions)
698-
if existErr != nil {
699-
assert.True(t, existErr == nil, "Init and Apply of temp existing resource failed")
700-
} else {
701-
options := setupOptionsVsiExtention(t, prefix, region, existingTerraformOptions)
702-
output, err := options.RunTestUpgrade()
703-
if !options.UpgradeTestSkipped {
704-
assert.Nil(t, err, "This should not have errored")
705-
assert.NotNil(t, output, "Expected some output")
706-
}
707-
}
708-
709-
// Check if "DO_NOT_DESTROY_ON_FAILURE" is set
710-
envVal, _ := os.LookupEnv("DO_NOT_DESTROY_ON_FAILURE")
711-
// Destroy the temporary existing resources if required
712-
if t.Failed() && strings.ToLower(envVal) == "true" {
713-
fmt.Println("Terratest failed. Debug the test and delete resources manually.")
714-
} else {
715-
logger.Log(t, "START: Destroy (existing resources)")
716-
terraform.Destroy(t, existingTerraformOptions)
717-
terraform.WorkspaceDelete(t, existingTerraformOptions, prefix)
718-
logger.Log(t, "END: Destroy (existing resources)")
719-
}
720-
}
721-
722556
func TestRunOverrideExample(t *testing.T) {
723557
t.Parallel()
724558

0 commit comments

Comments
 (0)