setuptest/initplanshow.go (44 lines of code) (raw):
package setuptest
import (
"testing"
"github.com/gruntwork-io/terratest/modules/terraform"
)
// InitPlanShow is a wrapper around terraform.InitAndPlanAndShowWithStructE
// It takes a test object as a parameter and returns a setuptest.Response.
//
// The response contains the temporary directory, the plan, the Terraform options and a cleanup function.
// The temporary directory is the directory containing a copy of the code specified by the Dirs func.
// The plan is the plan struct generated by terraform, which can be used by the check package.
// The cleanup function provides coherent logging and also will clean up the temporary directory - use with defer.
func (dtv DirTypeWithVars) InitPlanShow(t *testing.T) (Response, error) {
resp, err := setup(t, dtv.RootDir, dtv.TestDir, nil)
if err != nil {
return resp, err
}
resp.Options.Vars = dtv.Vars
resp.PlanStruct, err = terraform.InitAndPlanAndShowWithStructE(t, resp.Options)
return resp, err
}
// InitPlanShowWithPrepFunc is a wrapper around terraform.InitAndPlanAndShowWithStructE
// It takes a test object and a SetupTestPrepFunc as a parameter and returns a setuptest.Response.
// The PrepFunc is executed after the test has been copied to a tmp directory,
// allowing file modifications to be made before running Terraform.
//
// The response contains the temporary directory, the plan, the Terraform options and a cleanup function.
// The temporary directory is the directory containing a copy of the code specified by the Dirs func.
// The terraform options are the options used to run terraform and can be used by the apply functions.
// The plan is the plan struct generated by terraform, which can be used by the check package.
// The cleanup function provides coherent logging and also will clean up the temporary directory - use with defer.
func (dtv DirTypeWithVars) InitPlanShowWithPrepFunc(t *testing.T, f PrepFunc) (Response, error) {
resp, err := setup(t, dtv.RootDir, dtv.TestDir, f)
if err != nil {
return resp, err
}
resp.Options.Vars = dtv.Vars
resp.PlanStruct, err = terraform.InitAndPlanAndShowWithStructE(t, resp.Options)
return resp, err
}
// InitPlanShow is a wrapper around terraform.InitAndPlanAndShowWithStructE
// It takes a test object as a parameter and returns a setuptest.Response.
//
// The response contains the temporary directory, the plan, the Terraform options and a cleanup function.
// The temporary directory is the directory containing a copy of the code specified by the Dirs func.
// The plan is the plan struct generated by terraform, which can be used by the check package.
// The cleanup function is a provides coherent logging and also will clean up the temporary directory - use with defer.
func (dtvf DirTypeWithVarFiles) InitPlanShow(t *testing.T) (Response, error) {
resp, err := setup(t, dtvf.RootDir, dtvf.TestDir, nil)
if err != nil {
return resp, err
}
resp.Options.VarFiles = dtvf.VarFiles
plan, err := terraform.InitAndPlanAndShowWithStructE(t, resp.Options)
resp.PlanStruct = plan
return resp, err
}
// InitPlanShow is a wrapper around terraform.InitAndPlanAndShowWithStructE
// It takes a test object and a SetupTestPrepFunc as a parameter and returns a setuptest.Response.
// The PrepFunc is executed after the test has been coped to a tmp directory,
// allowing file modifications to be made before running terraform.
//
// The response contains the temporary directory, the plan, the Terraform options and a cleanup function.
// The temporary directory is the directory containing a copy of the code specified by the Dirs func.
// The terraform options are the options used to run terraform and can be used by the apply functions.
// The plan is the plan struct generated by terraform, which can be used by the check package.
// The cleanup function is a function which should be used with defer to clean up the temporary directory.
func (dtvf DirTypeWithVarFiles) InitPlanShowWithPrepFunc(t *testing.T, f PrepFunc) (Response, error) {
resp, err := setup(t, dtvf.RootDir, dtvf.TestDir, nil)
if err != nil {
return resp, err
}
resp.Options.VarFiles = dtvf.VarFiles
// Run terraform
resp.Options.VarFiles = dtvf.VarFiles
plan, err := terraform.InitAndPlanAndShowWithStructE(t, resp.Options)
resp.PlanStruct = plan
return resp, err
}