forked from runatlantis/atlantis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_step_runner.go
34 lines (29 loc) · 1.17 KB
/
init_step_runner.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 runtime
import (
"github.com/hashicorp/go-version"
"github.com/runatlantis/atlantis/server/events/models"
)
// InitStep runs `terraform init`.
type InitStepRunner struct {
TerraformExecutor TerraformExec
DefaultTFVersion *version.Version
}
func (i *InitStepRunner) Run(ctx models.ProjectCommandContext, extraArgs []string, path string) (string, error) {
tfVersion := i.DefaultTFVersion
if ctx.ProjectConfig != nil && ctx.ProjectConfig.TerraformVersion != nil {
tfVersion = ctx.ProjectConfig.TerraformVersion
}
terraformInitCmd := append([]string{"init", "-input=false", "-no-color"}, extraArgs...)
// If we're running < 0.9 we have to use `terraform get` instead of `init`.
if MustConstraint("< 0.9.0").Check(tfVersion) {
ctx.Log.Info("running terraform version %s so will use `get` instead of `init`", tfVersion)
terraformInitCmd = append([]string{"get", "-no-color"}, extraArgs...)
}
out, err := i.TerraformExecutor.RunCommandWithVersion(ctx.Log, path, terraformInitCmd, tfVersion, ctx.Workspace)
// Only include the init output if there was an error. Otherwise it's
// unnecessary and lengthens the comment.
if err != nil {
return out, err
}
return "", nil
}