Files
atlantis/server/events/runtime/init_step_runner.go
Andrii Nasinnyk 33c0a72add Add var step to workflows
Add new var step for setting environment variable in workflows.
2019-08-21 15:06:49 +02:00

35 lines
1.2 KiB
Go

package runtime
import (
version "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, envs map[string]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, envs, 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
}