Files
atlantis/server/events/runtime/init_step_runner.go
2019-03-27 14:47:48 -05:00

35 lines
1.1 KiB
Go

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.TerraformVersion != nil {
tfVersion = ctx.TerraformVersion
}
terraformInitCmd := append([]string{"init", "-input=false", "-no-color", "-upgrade"}, 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", "-upgrade"}, 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
}