8
8
"os"
9
9
"testing"
10
10
11
+ "github.com/gruntwork-io/terratest/modules/logger"
11
12
"github.com/gruntwork-io/terratest/modules/terraform"
12
13
"github.com/stretchr/testify/assert"
13
14
"github.com/stretchr/testify/require"
@@ -151,24 +152,24 @@ func TestRunStandardUpgradeSolution(t *testing.T) {
151
152
}
152
153
153
154
func 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" ,
167
171
}
168
172
169
- _ , initErr := terraform .InitE (t , options )
170
- assert .Nil (t , initErr , "This should not have errored" )
171
-
172
173
// Test the DA when using IBM owned encryption keys
173
174
var ibmOwnedEncrytionKeyTFVars = map [string ]interface {}{
174
175
"use_default_backup_encryption_key" : false ,
@@ -182,21 +183,26 @@ func TestPlanValidation(t *testing.T) {
182
183
"use_ibm_owned_encryption_key" : false ,
183
184
}
184
185
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 ,
189
190
}
190
191
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
+ })
196
205
}
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" )
200
206
}
201
207
}
202
208
0 commit comments