@@ -10,10 +10,12 @@ import (
1010 "testing"
1111 "time"
1212
13+ "github.com/hashicorp/terraform-exec/tfexec"
1314 "github.com/stretchr/testify/require"
1415
1516 "github.com/coder/preview"
1617 "github.com/coder/preview/internal/verify"
18+ "github.com/coder/preview/tfvars"
1719 "github.com/coder/preview/types"
1820)
1921
@@ -102,11 +104,11 @@ func Test_VerifyE2E(t *testing.T) {
102104
103105 entryWrkPath := t .TempDir ()
104106
105- for _ , tfexec := range tfexecs {
106- tfexec := tfexec
107+ for _ , tfexecutable := range tfexecs {
108+ tfexecutable := tfexecutable
107109
108- t .Run (tfexec .Version , func (t * testing.T ) {
109- wp := filepath .Join (entryWrkPath , tfexec .Version )
110+ t .Run (tfexecutable .Version , func (t * testing.T ) {
111+ wp := filepath .Join (entryWrkPath , tfexecutable .Version )
110112 err := os .MkdirAll (wp , 0755 )
111113 require .NoError (t , err , "creating working dir" )
112114
@@ -118,17 +120,27 @@ func Test_VerifyE2E(t *testing.T) {
118120 err = verify .CopyTFFS (wp , subFS )
119121 require .NoError (t , err , "copying test data to working dir" )
120122
121- exe , err := tfexec .WorkingDir (wp )
123+ exe , err := tfexecutable .WorkingDir (wp )
122124 require .NoError (t , err , "creating working executable" )
123125
124126 ctx , cancel := context .WithTimeout (context .Background (), time .Minute * 2 )
125127 defer cancel ()
126128 err = exe .Init (ctx )
127129 require .NoError (t , err , "terraform init" )
128130
131+ tfVarFiles , err := tfvars .TFVarFiles ("" , subFS )
132+ require .NoError (t , err , "loading tfvars files" )
133+
134+ planOpts := make ([]tfexec.PlanOption , 0 )
135+ applyOpts := make ([]tfexec.ApplyOption , 0 )
136+ for _ , varFile := range tfVarFiles {
137+ planOpts = append (planOpts , tfexec .VarFile (varFile ))
138+ applyOpts = append (applyOpts , tfexec .VarFile (varFile ))
139+ }
140+
129141 planOutFile := "tfplan"
130142 planOutPath := filepath .Join (wp , planOutFile )
131- _ , err = exe .Plan (ctx , planOutPath )
143+ _ , err = exe .Plan (ctx , planOutPath , planOpts ... )
132144 require .NoError (t , err , "terraform plan" )
133145
134146 plan , err := exe .ShowPlan (ctx , planOutPath )
@@ -141,7 +153,7 @@ func Test_VerifyE2E(t *testing.T) {
141153 err = os .WriteFile (filepath .Join (wp , "plan.json" ), pd , 0644 )
142154 require .NoError (t , err , "writing plan.json" )
143155
144- _ , err = exe .Apply (ctx )
156+ _ , err = exe .Apply (ctx , applyOpts ... )
145157 require .NoError (t , err , "terraform apply" )
146158
147159 state , err := exe .Show (ctx )
0 commit comments