77 "strings"
88 "testing"
99
10+ "github.com/IBM/go-sdk-core/v5/core"
1011 "github.com/gruntwork-io/terratest/modules/files"
1112 "github.com/gruntwork-io/terratest/modules/logger"
1213 "github.com/gruntwork-io/terratest/modules/random"
@@ -21,6 +22,9 @@ import (
2122 "github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testschematic"
2223)
2324
25+ /*
26+ Global variables
27+ */
2428const basicExampleTerraformDir = "examples/basic"
2529const customSecurityGroupExampleTerraformDir = "examples/custom_security_group"
2630const defaultExampleTerraformDir = "examples/default"
@@ -32,9 +36,8 @@ const noprefixExampleTerraformDir = "examples/no-prefix"
3236const vpcWithDnsExampleTerraformDir = "examples/vpc-with-dns"
3337const fullyConfigFlavorDir = "solutions/fully-configurable"
3438const resourceGroup = "geretain-test-resources"
35-
36- // Define a struct with fields that match the structure of the YAML data
3739const yamlLocation = "../common-dev-assets/common-go-assets/common-permanent-resources.yaml"
40+ const terraformVersion = "terraform_v1.10" // This should match the version in the ibm_catalog.json
3841
3942var permanentResources map [string ]interface {}
4043
@@ -198,18 +201,10 @@ func TestRunVpcWithDnsExample(t *testing.T) {
198201func TestFullyConfigurable (t * testing.T ) {
199202 t .Parallel ()
200203
201- // Verify ibmcloud_api_key variable is set
202- checkVariable := "TF_VAR_ibmcloud_api_key"
203- val , present := os .LookupEnv (checkVariable )
204- require .True (t , present , checkVariable + " environment variable not set" )
205- require .NotEqual (t , "" , val , checkVariable + " environment variable is empty" )
206-
207- prefix := "vpc-da"
208-
209204 options := testschematic .TestSchematicOptionsDefault (& testschematic.TestSchematicOptions {
210205 Testing : t ,
211206 Region : "eu-de" ,
212- Prefix : prefix ,
207+ Prefix : "vpc-da" ,
213208 TarIncludePatterns : []string {
214209 "*.tf" ,
215210 "dynamic_values/*.tf" ,
@@ -220,6 +215,7 @@ func TestFullyConfigurable(t *testing.T) {
220215 Tags : []string {"vpc-da-test" },
221216 DeleteWorkspaceOnFail : false ,
222217 WaitJobCompleteMinutes : 120 ,
218+ TerraformVersion : terraformVersion ,
223219 })
224220
225221 options .TerraformVars = []testschematic.TestSchematicTerraformVar {
@@ -291,7 +287,7 @@ func TestFullyConfigurableWithFlowLogs(t *testing.T) {
291287 require .True (t , present , checkVariable + " environment variable not set" )
292288 require .NotEqual (t , "" , val , checkVariable + " environment variable is empty" )
293289
294- prefix := "vpc-da-fl"
290+ prefix := fmt . Sprintf ( "vpc-f-%s" , strings . ToLower ( random . UniqueId ()))
295291 existingTerraformOptions := setupTerraform (t , prefix , "./existing-resources" )
296292
297293 options := testschematic .TestSchematicOptionsDefault (& testschematic.TestSchematicOptions {
@@ -308,6 +304,7 @@ func TestFullyConfigurableWithFlowLogs(t *testing.T) {
308304 Tags : []string {"vpc-da-test" },
309305 DeleteWorkspaceOnFail : false ,
310306 WaitJobCompleteMinutes : 120 ,
307+ TerraformVersion : terraformVersion ,
311308 })
312309
313310 options .TerraformVars = []testschematic.TestSchematicTerraformVar {
@@ -322,7 +319,7 @@ func TestFullyConfigurableWithFlowLogs(t *testing.T) {
322319 {Name : "kms_encryption_enabled_bucket" , Value : "true" , DataType : "bool" },
323320 {Name : "existing_kms_instance_crn" , Value : permanentResources ["hpcs_south_crn" ], DataType : "string" },
324321 {Name : "vpe_gateway_cloud_services" , Value : []map [string ]string {{"service_name" : "kms" }, {"service_name" : "cloud-object-storage" }}, DataType : "list(object{})" },
325- {Name : "vpe_gateway_cloud_service_by_crn" , Value : []map [string ]string {{"crn" : terraform .Output (t , existingTerraformOptions , "postgresql_db_crn" )}}, DataType : "list(object{})" },
322+ {Name : "vpe_gateway_cloud_service_by_crn" , Value : []map [string ]string {{"crn" : terraform .Output (t , existingTerraformOptions , "postgresql_db_crn" ), "vpe_name" : "pg" }}, DataType : "list(object{})" },
326323 {Name : "vpn_gateways" , Value : []map [string ]string {{"name" : options .Prefix + "-vpn" , "subnet_name" : "subnet-c" }}, DataType : "list(object{})" },
327324 }
328325
@@ -340,7 +337,7 @@ func TestRunUpgradeFullyConfigurable(t *testing.T) {
340337 require .True (t , present , checkVariable + " environment variable not set" )
341338 require .NotEqual (t , "" , val , checkVariable + " environment variable is empty" )
342339
343- prefix := "vpc-upg"
340+ prefix := fmt . Sprintf ( "vpc-u-%s" , strings . ToLower ( random . UniqueId ()))
344341 existingTerraformOptions := setupTerraform (t , prefix , "./existing-resources" )
345342
346343 options := testschematic .TestSchematicOptionsDefault (& testschematic.TestSchematicOptions {
@@ -353,10 +350,12 @@ func TestRunUpgradeFullyConfigurable(t *testing.T) {
353350 "dynamic_values/config_modules/*/*.tf" ,
354351 fullyConfigFlavorDir + "/*.tf" ,
355352 },
356- TemplateFolder : fullyConfigFlavorDir ,
357- Tags : []string {"vpc-da-test" },
358- DeleteWorkspaceOnFail : false ,
359- WaitJobCompleteMinutes : 120 ,
353+ TemplateFolder : fullyConfigFlavorDir ,
354+ Tags : []string {"vpc-da-test" },
355+ DeleteWorkspaceOnFail : false ,
356+ WaitJobCompleteMinutes : 120 ,
357+ CheckApplyResultForUpgrade : true ,
358+ TerraformVersion : terraformVersion ,
360359 })
361360
362361 options .TerraformVars = []testschematic.TestSchematicTerraformVar {
@@ -371,7 +370,7 @@ func TestRunUpgradeFullyConfigurable(t *testing.T) {
371370 {Name : "kms_encryption_enabled_bucket" , Value : "true" , DataType : "bool" },
372371 {Name : "existing_kms_instance_crn" , Value : permanentResources ["hpcs_south_crn" ], DataType : "string" },
373372 {Name : "vpe_gateway_cloud_services" , Value : []map [string ]string {{"service_name" : "kms" }, {"service_name" : "cloud-object-storage" }}, DataType : "list(object{})" },
374- {Name : "vpe_gateway_cloud_service_by_crn" , Value : []map [string ]string {{"crn" : terraform .Output (t , existingTerraformOptions , "postgresql_db_crn" )}}, DataType : "list(object{})" },
373+ {Name : "vpe_gateway_cloud_service_by_crn" , Value : []map [string ]string {{"crn" : terraform .Output (t , existingTerraformOptions , "postgresql_db_crn" ), "vpe_name" : "pg" }}, DataType : "list(object{})" },
375374 {Name : "vpn_gateways" , Value : []map [string ]string {{"name" : options .Prefix + "-vpn" , "subnet_name" : "subnet-c" }}, DataType : "list(object{})" },
376375 }
377376
@@ -409,7 +408,7 @@ func TestVpcAddonDefaultConfiguration(t *testing.T) {
409408
410409 options := testaddons .TestAddonsOptionsDefault (& testaddons.TestAddonOptions {
411410 Testing : t ,
412- Prefix : "vpc-def " ,
411+ Prefix : "vpc-ad " ,
413412 ResourceGroup : resourceGroup ,
414413 QuietMode : false , // Suppress logs except on failure
415414 })
@@ -424,29 +423,26 @@ func TestVpcAddonDefaultConfiguration(t *testing.T) {
424423 },
425424 )
426425
427- err := options .RunAddonTest ()
428- require .NoError (t , err )
429- }
430-
431- // TestDependencyPermutations runs dependency permutations for landing zone vpc and all its dependencies
432- func TestVpcDependencyPermutations (t * testing.T ) {
433-
434- t .Skip ("Skipping dependency permutations until the test is fixed" )
435- t .Parallel ()
436- options := testaddons .TestAddonsOptionsDefault (& testaddons.TestAddonOptions {
437- Testing : t ,
438- Prefix : "vpc-per" ,
439- AddonConfig : cloudinfo.AddonConfig {
440- OfferingName : "deploy-arch-ibm-slz-vpc" ,
426+ // Disable target / route creation to prevent hitting quota in account
427+ options .AddonConfig .Dependencies = []cloudinfo.AddonConfig {
428+ {
429+ OfferingName : "deploy-arch-ibm-cloud-monitoring" ,
441430 OfferingFlavor : "fully-configurable" ,
442431 Inputs : map [string ]interface {}{
443- "prefix" : "vpc-per" ,
444- "region" : "us-south" ,
445- "existing_cos_instance_crn" : permanentResources ["general_test_storage_cos_instance_crn" ],
432+ "enable_metrics_routing_to_cloud_monitoring" : false ,
446433 },
434+ Enabled : core .BoolPtr (true ),
447435 },
448- })
436+ {
437+ OfferingName : "deploy-arch-ibm-activity-tracker" ,
438+ OfferingFlavor : "fully-configurable" ,
439+ Inputs : map [string ]interface {}{
440+ "enable_activity_tracker_event_routing_to_cloud_logs" : false ,
441+ },
442+ Enabled : core .BoolPtr (true ),
443+ },
444+ }
449445
450- err := options .RunAddonPermutationTest ()
451- assert .NoError (t , err , "Dependency permutation test should not fail" )
446+ err := options .RunAddonTest ()
447+ require .NoError (t , err )
452448}
0 commit comments