@@ -4,6 +4,7 @@ package test
44import (
55 "fmt"
66 "log"
7+ "math/rand"
78 "os"
89 "strings"
910 "testing"
@@ -32,6 +33,14 @@ const yamlLocation = "../common-dev-assets/common-go-assets/common-permanent-res
3233
3334var permanentResources map [string ]interface {}
3435
36+ // Current supported Event Notification regions
37+ var validRegions = []string {
38+ "us-south" ,
39+ "eu-de" ,
40+ "eu-gb" ,
41+ "au-syd" ,
42+ }
43+
3544// TestMain will be run before any parallel tests, used to read data from yaml for use with tests
3645func TestMain (m * testing.M ) {
3746
@@ -49,27 +58,17 @@ func setupOptions(t *testing.T, prefix string) *testhelper.TestOptions {
4958 Testing : t ,
5059 TerraformDir : completeExampleTerraformDir ,
5160 Prefix : prefix ,
61+ Region : validRegions [rand .Intn (len (validRegions ))],
5262 /*
5363 Comment out the 'ResourceGroup' input to force this tests to create a unique resource group. This is because
5464 there is a restriction with the Event Notification service, which allows only one Lite plan instance per resource group.
5565 */
5666 // ResourceGroup: resourceGroup,
57- BestRegionYAMLPath : "../common-dev-assets/common-go-assets/cloudinfo-region-secmgr-prefs.yaml" ,
5867 })
5968
6069 return options
6170}
6271
63- func TestRunCompleteExample (t * testing.T ) {
64- t .Parallel ()
65-
66- options := setupOptions (t , "secrets-mgr" )
67-
68- output , err := options .RunTestConsistency ()
69- assert .Nil (t , err , "This should not have errored" )
70- assert .NotNil (t , output , "Expected some output" )
71- }
72-
7372func TestRunUpgradeExample (t * testing.T ) {
7473 t .Parallel ()
7574
@@ -82,38 +81,6 @@ func TestRunUpgradeExample(t *testing.T) {
8281 }
8382}
8483
85- func TestFSCloudInSchematics (t * testing.T ) {
86- t .Parallel ()
87-
88- options := testschematic .TestSchematicOptionsDefault (& testschematic.TestSchematicOptions {
89- Testing : t ,
90- Prefix : "sm-fscloud" ,
91- TarIncludePatterns : []string {
92- "*.tf" ,
93- fscloudExampleTerraformDir + "/*.tf" ,
94- "modules/fscloud/*.tf" ,
95- },
96- BestRegionYAMLPath : "../common-dev-assets/common-go-assets/cloudinfo-region-secmgr-prefs.yaml" ,
97- // ResourceGroup: resourceGroup,
98- TemplateFolder : fscloudExampleTerraformDir ,
99- Tags : []string {"test-schematic" },
100- DeleteWorkspaceOnFail : false ,
101- WaitJobCompleteMinutes : 60 ,
102- })
103-
104- options .TerraformVars = []testschematic.TestSchematicTerraformVar {
105- {Name : "ibmcloud_api_key" , Value : options .RequiredEnvironmentVars ["TF_VAR_ibmcloud_api_key" ], DataType : "string" , Secure : true },
106- {Name : "region" , Value : options .Region , DataType : "string" },
107- {Name : "prefix" , Value : options .Prefix , DataType : "string" },
108- {Name : "existing_kms_instance_guid" , Value : permanentResources ["hpcs_south" ], DataType : "string" },
109- {Name : "kms_key_crn" , Value : permanentResources ["hpcs_south_root_key_crn" ], DataType : "string" },
110- {Name : "sm_service_plan" , Value : "trial" , DataType : "string" },
111- }
112-
113- err := options .RunSchematicTest ()
114- assert .Nil (t , err , "This should not have errored" )
115- }
116-
11784func TestRunDASolutionSchematics (t * testing.T ) {
11885 t .Parallel ()
11986
@@ -133,13 +100,12 @@ func TestRunDASolutionSchematics(t *testing.T) {
133100 Tags : []string {"test-schematic" },
134101 DeleteWorkspaceOnFail : false ,
135102 WaitJobCompleteMinutes : 60 ,
136- BestRegionYAMLPath : "../common-dev-assets/common-go-assets/cloudinfo-region-secmgr-prefs.yaml" ,
137103 })
138104
139105 options .TerraformVars = []testschematic.TestSchematicTerraformVar {
140106 {Name : "ibmcloud_api_key" , Value : options .RequiredEnvironmentVars ["TF_VAR_ibmcloud_api_key" ], DataType : "string" , Secure : true },
141107 {Name : "prefix" , Value : options .Prefix , DataType : "string" },
142- {Name : "region" , Value : options . Region , DataType : "string" },
108+ {Name : "region" , Value : validRegions [ rand . Intn ( len ( validRegions ))] , DataType : "string" },
143109 {Name : "resource_group_name" , Value : options .Prefix , DataType : "string" },
144110 {Name : "service_plan" , Value : "trial" , DataType : "string" },
145111 {Name : "allowed_network" , Value : "private-only" , DataType : "string" },
@@ -183,15 +149,6 @@ func GetSecretsManagerKey(sm_id string, sm_region string, sm_key_id string) *str
183149func TestRunExistingResourcesInstances (t * testing.T ) {
184150 t .Parallel ()
185151
186- // Init test options for DA to get the region, which is used for provisioning the existing resources
187- options := testhelper .TestOptionsDefault (& testhelper.TestOptions {
188- Testing : t ,
189- TerraformDir : solutionsTerraformDir ,
190- // Do not hard fail the test if the implicit destroy steps fail to allow a full destroy of resource to occur
191- ImplicitRequired : false ,
192- BestRegionYAMLPath : "../common-dev-assets/common-go-assets/cloudinfo-region-secmgr-prefs.yaml" ,
193- })
194-
195152 // ------------------------------------------------------------------------------------
196153 // Provision Event Notification, KMS key and resource group first
197154 // ------------------------------------------------------------------------------------
@@ -200,7 +157,6 @@ func TestRunExistingResourcesInstances(t *testing.T) {
200157 realTerraformDir := "./existing-resources"
201158 tempTerraformDir , _ := files .CopyTerraformFolderToTemp (realTerraformDir , fmt .Sprintf (prefix + "-%s" , strings .ToLower (random .UniqueId ())))
202159 tags := common .GetTagsFromTravis ()
203- region := "us-south"
204160
205161 // Verify ibmcloud_api_key variable is set
206162 checkVariable := "TF_VAR_ibmcloud_api_key"
@@ -212,7 +168,7 @@ func TestRunExistingResourcesInstances(t *testing.T) {
212168 TerraformDir : tempTerraformDir ,
213169 Vars : map [string ]interface {}{
214170 "prefix" : prefix ,
215- "region" : options . Region ,
171+ "region" : validRegions [ rand . Intn ( len ( validRegions ))] ,
216172 "resource_tags" : tags ,
217173 },
218174 // Set Upgrade to true to ensure latest version of providers and modules are used by terratest.
@@ -225,17 +181,25 @@ func TestRunExistingResourcesInstances(t *testing.T) {
225181 if existErr != nil {
226182 assert .True (t , existErr == nil , "Init and Apply of temp existing resource failed" )
227183 } else {
228- // add existing resources to previously created options
229- options .TerraformVars = map [string ]interface {}{
230- "ibmcloud_api_key" : os .Getenv ("TF_VAR_ibmcloud_api_key" ),
231- "region" : region ,
232- "resource_group_name" : terraform .Output (t , existingTerraformOptions , "resource_group_name" ),
233- "use_existing_resource_group" : true ,
234- "existing_event_notification_instance_crn" : terraform .Output (t , existingTerraformOptions , "event_notification_instance_crn" ),
235- "existing_secrets_manager_kms_key_crn" : terraform .Output (t , existingTerraformOptions , "secrets_manager_kms_key_crn" ),
236- "existing_kms_instance_crn" : terraform .Output (t , existingTerraformOptions , "secrets_manager_kms_instance_crn" ),
237- "service_plan" : "trial" ,
238- }
184+ options := testhelper .TestOptionsDefault (& testhelper.TestOptions {
185+ Testing : t ,
186+ TerraformDir : solutionsTerraformDir ,
187+ // Do not hard fail the test if the implicit destroy steps fail to allow a full destroy of resource to occur
188+ ImplicitRequired : false ,
189+ TerraformVars : map [string ]interface {}{
190+ "ibmcloud_api_key" : os .Getenv ("TF_VAR_ibmcloud_api_key" ),
191+ "region" : validRegions [rand .Intn (len (validRegions ))],
192+ "resource_group_name" : terraform .Output (t , existingTerraformOptions , "resource_group_name" ),
193+ "use_existing_resource_group" : true ,
194+ "existing_event_notification_instance_crn" : terraform .Output (t , existingTerraformOptions , "event_notification_instance_crn" ),
195+ "existing_secrets_manager_kms_key_crn" : terraform .Output (t , existingTerraformOptions , "secrets_manager_kms_key_crn" ),
196+ "existing_kms_instance_crn" : terraform .Output (t , existingTerraformOptions , "secrets_manager_kms_instance_crn" ),
197+ "service_plan" : "trial" ,
198+ "existing_secrets_manager_crn" : terraform .Output (t , existingTerraformOptions , "secrets_manager_instance_crn" ),
199+ "iam_engine_enabled" : true ,
200+ "private_engine_enabled" : true ,
201+ },
202+ })
239203
240204 output , err := options .RunTestConsistency ()
241205 assert .Nil (t , err , "This should not have errored" )
0 commit comments