github.com/someshkoli/terratest@v0.41.1/modules/terraform/init.go (about) 1 package terraform 2 3 import ( 4 "fmt" 5 6 "github.com/gruntwork-io/terratest/modules/testing" 7 ) 8 9 // Init calls terraform init and return stdout/stderr. 10 func Init(t testing.TestingT, options *Options) string { 11 out, err := InitE(t, options) 12 if err != nil { 13 t.Fatal(err) 14 } 15 return out 16 } 17 18 // InitE calls terraform init and return stdout/stderr. 19 func InitE(t testing.TestingT, options *Options) (string, error) { 20 args := []string{"init", fmt.Sprintf("-upgrade=%t", options.Upgrade)} 21 22 // Append reconfigure option if specified 23 if options.Reconfigure { 24 args = append(args, "-reconfigure") 25 } 26 // Append combination of migrate-state and force-copy to suppress answer prompt 27 if options.MigrateState { 28 args = append(args, "-migrate-state", "-force-copy") 29 } 30 31 args = append(args, FormatTerraformBackendConfigAsArgs(options.BackendConfig)...) 32 args = append(args, FormatTerraformPluginDirAsArgs(options.PluginDir)...) 33 return RunTerraformCommandE(t, options, args...) 34 }