Skip to content

Commit

Permalink
Quote the -out variable in terraform plan.
Browse files Browse the repository at this point in the history
Fixes #290. In Bitbucket Server, the repo owner name can have spaces.
This causes errors when running terraform plan -out path with spaces so
we need to quote it: terraform plan -out "path with spaces".
  • Loading branch information
lkysow committed Sep 27, 2018
1 parent a0de1c8 commit c56aa9e
Showing 3 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion server/events/models/models.go
Original file line number Diff line number Diff line change
@@ -31,10 +31,11 @@ import (
// Repo is a VCS repository.
type Repo struct {
// FullName is the owner and repo name separated
// by a "/", ex. "runatlantis/atlantis" or "gitlab/subgroup/atlantis"
// by a "/", ex. "runatlantis/atlantis", "gitlab/subgroup/atlantis", "Bitbucket Server/atlantis".
FullName string
// Owner is just the repo owner, ex. "runatlantis" or "gitlab/subgroup".
// This may contain /'s in the case of GitLab subgroups.
// This may contain spaces in the case of Bitbucket Server.
Owner string
// Name is just the repo name, ex. "atlantis". This will never have
// /'s in it.
4 changes: 3 additions & 1 deletion server/events/runtime/plan_step_runner.go
Original file line number Diff line number Diff line change
@@ -110,7 +110,9 @@ func (p *PlanStepRunner) buildPlanCmd(ctx models.ProjectCommandContext, extraArg
}

argList := [][]string{
{"plan", "-input=false", "-refresh", "-no-color", "-out", planFile},
// NOTE: we need to quote the plan filename because Bitbucket Server can
// have spaces in its repo owner names.
{"plan", "-input=false", "-refresh", "-no-color", "-out", fmt.Sprintf("%q", planFile)},
tfVars,
extraArgs,
ctx.CommentArgs,
13 changes: 7 additions & 6 deletions server/events/runtime/plan_step_runner_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package runtime_test

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
@@ -58,7 +59,7 @@ func TestRun_NoWorkspaceIn08(t *testing.T) {
"-refresh",
"-no-color",
"-out",
"/path/default.tfplan",
"\"/path/default.tfplan\"",
"-var",
"atlantis_user=username",
"-var",
@@ -187,7 +188,7 @@ func TestRun_SwitchesWorkspace(t *testing.T) {
"-refresh",
"-no-color",
"-out",
"/path/workspace.tfplan",
"\"/path/workspace.tfplan\"",
"-var",
"atlantis_user=username",
"-var",
@@ -252,7 +253,7 @@ func TestRun_CreatesWorkspace(t *testing.T) {
"-refresh",
"-no-color",
"-out",
"/path/workspace.tfplan",
"\"/path/workspace.tfplan\"",
"-var",
"atlantis_user=username",
"-var",
@@ -306,7 +307,7 @@ func TestRun_NoWorkspaceSwitchIfNotNecessary(t *testing.T) {
"-refresh",
"-no-color",
"-out",
"/path/workspace.tfplan",
"\"/path/workspace.tfplan\"",
"-var",
"atlantis_user=username",
"-var",
@@ -368,7 +369,7 @@ func TestRun_AddsEnvVarFile(t *testing.T) {
"-refresh",
"-no-color",
"-out",
filepath.Join(tmpDir, "workspace.tfplan"),
fmt.Sprintf("%q", filepath.Join(tmpDir, "workspace.tfplan")),
"-var",
"atlantis_user=username",
"-var",
@@ -423,7 +424,7 @@ func TestRun_UsesDiffPathForProject(t *testing.T) {
"-refresh",
"-no-color",
"-out",
"/path/projectname-default.tfplan",
"\"/path/projectname-default.tfplan\"",
"-var",
"atlantis_user=username",
"-var",

0 comments on commit c56aa9e

Please sign in to comment.