diff --git a/server/events/runtime/run_step_runner.go b/server/events/runtime/run_step_runner.go index f7a7cb2fce..1d1f10007a 100644 --- a/server/events/runtime/run_step_runner.go +++ b/server/events/runtime/run_step_runner.go @@ -6,13 +6,15 @@ import ( "os/exec" "path/filepath" - 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) { @@ -32,6 +34,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 d12dc7cc8e..f30f250b60 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"), }, } @@ -70,6 +75,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 a42d7bd825..332768e563 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" ) @@ -177,6 +177,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 5289c58957..eaa29f13b9 100644 --- a/server/server.go +++ b/server/server.go @@ -283,6 +283,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { }, RunStepRunner: &runtime.RunStepRunner{ DefaultTFVersion: defaultTfVersion, + TerraformBinDir: terraformClient.TerraformBinDir(), }, PullApprovedChecker: vcsClient, WorkingDir: workingDir,