forked from openshift/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
terraform.go
44 lines (37 loc) · 1.06 KB
/
terraform.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
35
36
37
38
39
40
41
42
43
44
package terraform
import (
"fmt"
"path"
"github.com/pkg/errors"
)
func terraformExec(clusterDir string, args ...string) error {
// Create an executor
ex, err := newExecutor()
if err != nil {
return errors.Wrap(err, "failed to create Terraform executor")
}
err = ex.execute(clusterDir, args...)
if err != nil {
return errors.Wrap(err, "failed to execute Terraform")
}
return nil
}
// Apply runs "terraform apply" in the given directory. It returns the absolute
// path of the tfstate file, rooted in the specified directory, along with any
// errors from Terraform.
func Apply(dir string, extraArgs ...string) (string, error) {
stateFileName := "terraform.tfstate"
defaultArgs := []string{
"apply",
"-auto-approve",
"-input=false",
"-no-color",
fmt.Sprintf("-state=%s", stateFileName),
}
args := append(defaultArgs, extraArgs...)
return path.Join(dir, stateFileName), terraformExec(dir, args...)
}
// Init runs "terraform init" in the given directory.
func Init(dir string) error {
return terraformExec(dir, "init", "-input=false", "-no-color")
}