88 "os"
99 "testing"
1010
11+ "github.com/gruntwork-io/terratest/modules/logger"
1112 "github.com/gruntwork-io/terratest/modules/terraform"
1213 "github.com/stretchr/testify/assert"
1314 "github.com/stretchr/testify/require"
@@ -151,24 +152,24 @@ func TestRunStandardUpgradeSolution(t *testing.T) {
151152}
152153
153154func TestPlanValidation (t * testing.T ) {
154- t .Parallel ()
155-
156- options := & terraform.Options {
157- TerraformDir : "../" + standardSolutionTerraformDir ,
158- Vars : map [string ]interface {}{
159- "prefix" : "validate-plan" ,
160- "region" : "us-south" ,
161- "kms_endpoint_type" : "public" ,
162- "provider_visibility" : "public" ,
163- "resource_group_name" : "validate-plan" ,
164- "admin_pass" : GetRandomAdminPassword (t ),
165- },
166- Upgrade : true ,
155+ options := testhelper .TestOptionsDefault (& testhelper.TestOptions {
156+ Testing : t ,
157+ TerraformDir : standardSolutionTerraformDir ,
158+ Prefix : "validate-plan" ,
159+ ResourceGroup : resourceGroup ,
160+ Region : "us-south" , // skip VPC region picker
161+ })
162+ options .TestSetup ()
163+ options .TerraformOptions .NoColor = true
164+ options .TerraformOptions .Logger = logger .Discard
165+ options .TerraformOptions .Vars = map [string ]interface {}{
166+ "prefix" : options .Prefix ,
167+ "region" : "us-south" ,
168+ "kms_endpoint_type" : "public" ,
169+ "provider_visibility" : "public" ,
170+ "resource_group_name" : "validate-plan" ,
167171 }
168172
169- _ , initErr := terraform .InitE (t , options )
170- assert .Nil (t , initErr , "This should not have errored" )
171-
172173 // Test the DA when using IBM owned encryption keys
173174 var ibmOwnedEncrytionKeyTFVars = map [string ]interface {}{
174175 "use_default_backup_encryption_key" : false ,
@@ -182,21 +183,26 @@ func TestPlanValidation(t *testing.T) {
182183 "use_ibm_owned_encryption_key" : false ,
183184 }
184185
185- // Create a list (slice) of the maps
186- tfVarsList := [ ]map [string ]interface {}{
187- ibmOwnedEncrytionKeyTFVars ,
188- notIbmOwnedEncrytionKeyTFVars ,
186+ // Create a map of the variables
187+ tfVarsMap := map [ string ]map [string ]interface {}{
188+ "ibmOwnedEncrytionKeyTFVars" : ibmOwnedEncrytionKeyTFVars ,
189+ "notIbmOwnedEncrytionKeyTFVars" : notIbmOwnedEncrytionKeyTFVars ,
189190 }
190191
191- // Iterate over the slice of maps
192- for _ , tfVars := range tfVarsList {
193- // Iterate over the keys and values in each map
194- for key , value := range tfVars {
195- options .Vars [key ] = value
192+ _ , initErr := terraform .InitE (t , options .TerraformOptions )
193+ if assert .Nil (t , initErr , "This should not have errored" ) {
194+ // Iterate over the slice of maps
195+ for name , tfVars := range tfVarsMap {
196+ t .Run (name , func (t * testing.T ) {
197+ // Iterate over the keys and values in each map
198+ for key , value := range tfVars {
199+ options .TerraformOptions .Vars [key ] = value
200+ }
201+ output , err := terraform .PlanE (t , options .TerraformOptions )
202+ assert .Nil (t , err , "This should not have errored" )
203+ assert .NotNil (t , output , "Expected some output" )
204+ })
196205 }
197- output , err := terraform .PlanE (t , options )
198- assert .Nil (t , err , "This should not have errored" )
199- assert .NotNil (t , output , "Expected some output" )
200206 }
201207}
202208
0 commit comments