99 "strings"
1010 "testing"
1111
12+ "github.com/IBM/go-sdk-core/core"
1213 "github.com/gruntwork-io/terratest/modules/files"
1314 "github.com/gruntwork-io/terratest/modules/logger"
1415 "github.com/gruntwork-io/terratest/modules/random"
@@ -19,14 +20,16 @@ import (
1920 "github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/common"
2021 "github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testaddons"
2122 "github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testhelper"
23+ "github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testschematic"
2224)
2325
2426// Use existing resource group
2527const resourceGroup = "geretain-test-resources"
2628const basicExampleDir = "examples/basic"
2729const completeExampleDir = "examples/complete"
28- const standardSolutionTerraformDir = "solutions/fully-configurable"
30+ const fullyConfigurableSolutionTerraformDir = "solutions/fully-configurable"
2931const yamlLocation = "../common-dev-assets/common-go-assets/common-permanent-resources.yaml"
32+ const terraformVersion = "terraform_v1.10" // This should match the version in the ibm_catalog.json
3033
3134// Current supported regions for watsonx.ai Studio, Runtime and IBM watsonx platform (dataplatform.ibm.com)
3235var validRegions = []string {
@@ -111,21 +114,6 @@ func setupKMSKeyProtect(t *testing.T, region string, prefix string) *terraform.O
111114 return existingTerraformOptions
112115}
113116
114- // Cleanup the resources when KMS encryption key is created.
115- func cleanupResources (t * testing.T , terraformOptions * terraform.Options , prefix string ) {
116- // Check if "DO_NOT_DESTROY_ON_FAILURE" is set
117- envVal , _ := os .LookupEnv ("DO_NOT_DESTROY_ON_FAILURE" )
118- // Destroy the temporary existing resources if required
119- if t .Failed () && strings .ToLower (envVal ) == "true" {
120- fmt .Println ("Terratest failed. Debug the test and delete resources manually." )
121- } else {
122- logger .Log (t , "START: Destroy (existing resources)" )
123- terraform .Destroy (t , terraformOptions )
124- terraform .WorkspaceDelete (t , terraformOptions , prefix )
125- logger .Log (t , "END: Destroy (existing resources)" )
126- }
127- }
128-
129117func TestRunBasicExample (t * testing.T ) {
130118 t .Parallel ()
131119
@@ -145,21 +133,27 @@ func TestRunCompleteExample(t *testing.T) {
145133 assert .NotNil (t , output , "Expected some output" )
146134}
147135
148- // Test the DA
149- func TestRunStandardSolution (t * testing.T ) {
150- t .Parallel ()
151-
136+ func setupFullyConfigurableOptions (t * testing.T , prefix string ) * testschematic.TestSchematicOptions {
152137 var region = validRegions [rand .Intn (len (validRegions ))]
153138 prefixExistingRes := fmt .Sprintf ("wxai-da-%s" , strings .ToLower (random .UniqueId ()))
154139 existingTerraformOptions := setupKMSKeyProtect (t , region , prefixExistingRes )
155140
156141 // Deploy watsonx.ai DA using existing KP details
157- options := testhelper .TestOptionsDefault (& testhelper.TestOptions {
158- Testing : t ,
159- TerraformDir : standardSolutionTerraformDir ,
160- Prefix : "wxai" ,
161- Region : region ,
162- ResourceGroup : resourceGroup ,
142+ options := testschematic .TestSchematicOptionsDefault (& testschematic.TestSchematicOptions {
143+ Testing : t ,
144+ TemplateFolder : fullyConfigurableSolutionTerraformDir ,
145+ Prefix : "wxai-fc" ,
146+ Region : region ,
147+ ResourceGroup : resourceGroup ,
148+ TarIncludePatterns : []string {
149+ "modules/configure_project/*.tf" ,
150+ "modules/configure_project/scripts/*.sh" ,
151+ "modules/configure_user/*.tf" ,
152+ "modules/configure_user/scripts/*.sh" ,
153+ "modules/storage_delegation/*.tf" ,
154+ "*.tf" ,
155+ fullyConfigurableSolutionTerraformDir + "/*.tf" ,
156+ },
163157 IgnoreDestroys : testhelper.Exemptions { // Ignore for consistency check
164158 List : []string {
165159 "module.watsonx_ai.module.configure_user.null_resource.configure_user" ,
@@ -172,72 +166,43 @@ func TestRunStandardSolution(t *testing.T) {
172166 "module.watsonx_ai.module.configure_user.null_resource.restrict_access" ,
173167 },
174168 },
169+ TerraformVersion : terraformVersion ,
175170 })
176- options .TerraformVars = map [string ]interface {}{
177- "prefix" : options .Prefix ,
178- "region" : options .Region ,
179- "existing_resource_group_name" : resourceGroup ,
180- "provider_visibility" : "public" ,
181- "watsonx_ai_project_name" : "wxai-da-prj" ,
182- "existing_kms_instance_crn" : terraform .Output (t , existingTerraformOptions , "key_protect_crn" ),
183- "kms_endpoint_type" : "public" ,
184- "existing_cos_instance_crn" : terraform .Output (t , existingTerraformOptions , "cos_crn" ),
185- "enable_cos_kms_encryption" : true ,
171+ options .TerraformVars = []testschematic.TestSchematicTerraformVar {
172+ {Name : "ibmcloud_api_key" , Value : options .RequiredEnvironmentVars ["TF_VAR_ibmcloud_api_key" ], DataType : "string" , Secure : true },
173+ {Name : "prefix" , Value : options .Prefix , DataType : "string" },
174+ {Name : "region" , Value : options .Region , DataType : "string" },
175+ {Name : "existing_resource_group_name" , Value : resourceGroup , DataType : "string" },
176+ {Name : "provider_visibility" , Value : "private" , DataType : "string" },
177+ {Name : "watsonx_ai_project_name" , Value : "wxai-ug-prj" , DataType : "string" },
178+ {Name : "existing_kms_instance_crn" , Value : terraform .Output (t , existingTerraformOptions , "key_protect_crn" ), DataType : "string" },
179+ {Name : "kms_endpoint_type" , Value : "private" , DataType : "string" },
180+ {Name : "existing_cos_instance_crn" , Value : terraform .Output (t , existingTerraformOptions , "cos_crn" ), DataType : "string" },
181+ {Name : "enable_cos_kms_encryption" , Value : true , DataType : "string" },
186182 }
183+ return options
184+ }
187185
188- output , err := options . RunTestConsistency ()
189- assert . Nil ( t , err , "This should not have errored" )
190- assert . NotNil ( t , output , "Expected some output" )
186+ // Test the DA
187+ func TestRunFullyConfigurableSolutionSchematics ( t * testing. T ) {
188+ t . Parallel ( )
191189
192- cleanupResources (t , existingTerraformOptions , prefixExistingRes )
190+ options := setupFullyConfigurableOptions (t , "wxai" )
191+
192+ err := options .RunSchematicTest ()
193+ assert .Nil (t , err , "This should not have errored" )
193194}
194195
195- func TestRunStandardUpgradeSolution (t * testing.T ) {
196+ func TestRunFullyConfigurableUpgradeSolutionSchematics (t * testing.T ) {
196197 t .Parallel ()
197198
198- var region = validRegions [rand .Intn (len (validRegions ))]
199- prefixExistingRes := fmt .Sprintf ("wxai-da-%s" , strings .ToLower (random .UniqueId ()))
200- existingTerraformOptions := setupKMSKeyProtect (t , region , prefixExistingRes )
199+ options := setupFullyConfigurableOptions (t , "wxai-up" )
200+ options .CheckApplyResultForUpgrade = true
201201
202- // Deploy watsonx.ai DA using existing KP details
203- options := testhelper .TestOptionsDefault (& testhelper.TestOptions {
204- Testing : t ,
205- TerraformDir : standardSolutionTerraformDir ,
206- Prefix : "wxai-upg" ,
207- Region : region ,
208- ResourceGroup : resourceGroup ,
209- IgnoreDestroys : testhelper.Exemptions { // Ignore for consistency check
210- List : []string {
211- "module.watsonx_ai.module.configure_user.null_resource.configure_user" ,
212- "module.watsonx_ai.module.configure_user.null_resource.restrict_access" ,
213- },
214- },
215- IgnoreUpdates : testhelper.Exemptions { // Ignore for consistency check
216- List : []string {
217- "module.watsonx_ai.module.configure_user.null_resource.configure_user" ,
218- "module.watsonx_ai.module.configure_user.null_resource.restrict_access" ,
219- },
220- },
221- })
222- options .TerraformVars = map [string ]interface {}{
223- "prefix" : options .Prefix ,
224- "region" : options .Region ,
225- "existing_resource_group_name" : resourceGroup ,
226- "provider_visibility" : "public" ,
227- "watsonx_ai_project_name" : "wxai-ug-prj" ,
228- "existing_kms_instance_crn" : terraform .Output (t , existingTerraformOptions , "key_protect_crn" ),
229- "kms_endpoint_type" : "public" ,
230- "existing_cos_instance_crn" : terraform .Output (t , existingTerraformOptions , "cos_crn" ),
231- "enable_cos_kms_encryption" : true ,
232- }
233-
234- output , err := options .RunTestUpgrade ()
202+ err := options .RunSchematicUpgradeTest ()
235203 if ! options .UpgradeTestSkipped {
236204 assert .Nil (t , err , "This should not have errored" )
237- assert .NotNil (t , output , "Expected some output" )
238205 }
239-
240- cleanupResources (t , existingTerraformOptions , prefixExistingRes )
241206}
242207
243208func TestWatsonxaiDefaultConfiguration (t * testing.T ) {
@@ -259,28 +224,26 @@ func TestWatsonxaiDefaultConfiguration(t *testing.T) {
259224 },
260225 )
261226
262- err := options .RunAddonTest ()
263- require .NoError (t , err )
264- }
265-
266- // TestDependencyPermutations runs dependency permutations for watsonx.ai and all its dependencies
267- func TestDependencyPermutations (t * testing.T ) {
268- t .Skip ("Skipping dependency permutations" )
269- t .Parallel ()
270-
271- options := testaddons .TestAddonsOptionsDefault (& testaddons.TestAddonOptions {
272- Testing : t ,
273- Prefix : "ai-perm" ,
274- AddonConfig : cloudinfo.AddonConfig {
275- OfferingName : "deploy-arch-ibm-watsonx-ai" ,
227+ // Disable target / route creation to prevent hitting quota in account
228+ options .AddonConfig .Dependencies = []cloudinfo.AddonConfig {
229+ {
230+ OfferingName : "deploy-arch-ibm-cloud-monitoring" ,
276231 OfferingFlavor : "fully-configurable" ,
277232 Inputs : map [string ]interface {}{
278- "prefix" : "ai-perm" ,
279- "existing_resource_group_name" : resourceGroup ,
233+ "enable_metrics_routing_to_cloud_monitoring" : false ,
280234 },
235+ Enabled : core .BoolPtr (true ),
281236 },
282- })
237+ {
238+ OfferingName : "deploy-arch-ibm-activity-tracker" ,
239+ OfferingFlavor : "fully-configurable" ,
240+ Inputs : map [string ]interface {}{
241+ "enable_activity_tracker_event_routing_to_cloud_logs" : false ,
242+ },
243+ Enabled : core .BoolPtr (true ),
244+ },
245+ }
283246
284- err := options .RunAddonPermutationTest ()
285- assert .NoError (t , err , "Dependency permutation test should not fail" )
247+ err := options .RunAddonTest ()
248+ require .NoError (t , err )
286249}
0 commit comments