diff --git a/server/events/runtime/run_step_runner.go b/server/events/runtime/run_step_runner.go index 7c4eaf18ee..58752b6153 100644 --- a/server/events/runtime/run_step_runner.go +++ b/server/events/runtime/run_step_runner.go @@ -7,13 +7,15 @@ import ( "path/filepath" "strings" - version "github.com/hashicorp/go-version" + "github.com/hashicorp/go-version" "github.com/runatlantis/atlantis/server/events/models" ) // RunStepRunner runs custom commands. type RunStepRunner struct { DefaultTFVersion *version.Version + // TerraformBinDir is the directory where Atlantis downloads Terraform binaries. + TerraformBinDir string } func (r *RunStepRunner) Run(ctx models.ProjectCommandContext, command string, path string) (string, error) { @@ -34,6 +36,7 @@ func (r *RunStepRunner) Run(ctx models.ProjectCommandContext, command string, pa "HEAD_BRANCH_NAME": ctx.Pull.HeadBranch, "HEAD_REPO_NAME": ctx.HeadRepo.Name, "HEAD_REPO_OWNER": ctx.HeadRepo.Owner, + "PATH": fmt.Sprintf("%s:%s", os.Getenv("PATH"), r.TerraformBinDir), "PLANFILE": filepath.Join(path, GetPlanFilename(ctx.Workspace, ctx.ProjectName)), "PROJECT_NAME": ctx.ProjectName, "PULL_AUTHOR": ctx.Pull.Author, diff --git a/server/events/runtime/run_step_runner_test.go b/server/events/runtime/run_step_runner_test.go index ebf8eb7afa..c6b993a2e2 100644 --- a/server/events/runtime/run_step_runner_test.go +++ b/server/events/runtime/run_step_runner_test.go @@ -1,10 +1,12 @@ package runtime_test import ( + "fmt" + "os" "strings" "testing" - version "github.com/hashicorp/go-version" + "github.com/hashicorp/go-version" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/runtime" "github.com/runatlantis/atlantis/server/logging" @@ -62,6 +64,9 @@ func TestRunStepRunner_Run(t *testing.T) { { Command: "echo user_name=$USER_NAME", ExpOut: "user_name=acme-user\n", + }, { + Command: "echo $PATH", + ExpOut: fmt.Sprintf("%s:%s\n", os.Getenv("PATH"), "/bin/dir"), }, { Command: "echo args=$COMMENT_ARGS", @@ -74,6 +79,7 @@ func TestRunStepRunner_Run(t *testing.T) { defaultVersion, _ := version.NewVersion("0.8") r := runtime.RunStepRunner{ DefaultTFVersion: defaultVersion, + TerraformBinDir: "/bin/dir", } for _, c := range cases { t.Run(c.Command, func(t *testing.T) { diff --git a/server/events/terraform/terraform_client.go b/server/events/terraform/terraform_client.go index 1677cf632a..51de5877f1 100644 --- a/server/events/terraform/terraform_client.go +++ b/server/events/terraform/terraform_client.go @@ -27,9 +27,9 @@ import ( "strings" "sync" - getter "github.com/hashicorp/go-getter" - version "github.com/hashicorp/go-version" - homedir "github.com/mitchellh/go-homedir" + "github.com/hashicorp/go-getter" + "github.com/hashicorp/go-version" + "github.com/mitchellh/go-homedir" "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/logging" ) @@ -184,6 +184,11 @@ func (c *DefaultClient) DefaultVersion() *version.Version { return c.defaultVersion } +// TerraformBinDir returns the directory where we download Terraform binaries. +func (c *DefaultClient) TerraformBinDir() string { + return c.binDir +} + // See Client.RunCommandWithVersion. func (c *DefaultClient) RunCommandWithVersion(log *logging.SimpleLogger, path string, args []string, v *version.Version, workspace string) (string, error) { tfCmd, cmd, err := c.prepCmd(log, v, workspace, path, args) diff --git a/server/server.go b/server/server.go index d02fff318a..1cbbfae725 100644 --- a/server/server.go +++ b/server/server.go @@ -290,6 +290,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { }, RunStepRunner: &runtime.RunStepRunner{ DefaultTFVersion: defaultTfVersion, + TerraformBinDir: terraformClient.TerraformBinDir(), }, PullApprovedChecker: vcsClient, WorkingDir: workingDir,