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