Skip to content

Commit c56aa9e

Browse files
committed
Quote the -out variable in terraform plan.
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".
1 parent a0de1c8 commit c56aa9e

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

server/events/models/models.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ import (
3131
// Repo is a VCS repository.
3232
type Repo struct {
3333
// FullName is the owner and repo name separated
34-
// by a "/", ex. "runatlantis/atlantis" or "gitlab/subgroup/atlantis"
34+
// by a "/", ex. "runatlantis/atlantis", "gitlab/subgroup/atlantis", "Bitbucket Server/atlantis".
3535
FullName string
3636
// Owner is just the repo owner, ex. "runatlantis" or "gitlab/subgroup".
3737
// This may contain /'s in the case of GitLab subgroups.
38+
// This may contain spaces in the case of Bitbucket Server.
3839
Owner string
3940
// Name is just the repo name, ex. "atlantis". This will never have
4041
// /'s in it.

server/events/runtime/plan_step_runner.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ func (p *PlanStepRunner) buildPlanCmd(ctx models.ProjectCommandContext, extraArg
110110
}
111111

112112
argList := [][]string{
113-
{"plan", "-input=false", "-refresh", "-no-color", "-out", planFile},
113+
// NOTE: we need to quote the plan filename because Bitbucket Server can
114+
// have spaces in its repo owner names.
115+
{"plan", "-input=false", "-refresh", "-no-color", "-out", fmt.Sprintf("%q", planFile)},
114116
tfVars,
115117
extraArgs,
116118
ctx.CommentArgs,

server/events/runtime/plan_step_runner_test.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package runtime_test
22

33
import (
4+
"fmt"
45
"io/ioutil"
56
"os"
67
"path/filepath"
@@ -58,7 +59,7 @@ func TestRun_NoWorkspaceIn08(t *testing.T) {
5859
"-refresh",
5960
"-no-color",
6061
"-out",
61-
"/path/default.tfplan",
62+
"\"/path/default.tfplan\"",
6263
"-var",
6364
"atlantis_user=username",
6465
"-var",
@@ -187,7 +188,7 @@ func TestRun_SwitchesWorkspace(t *testing.T) {
187188
"-refresh",
188189
"-no-color",
189190
"-out",
190-
"/path/workspace.tfplan",
191+
"\"/path/workspace.tfplan\"",
191192
"-var",
192193
"atlantis_user=username",
193194
"-var",
@@ -252,7 +253,7 @@ func TestRun_CreatesWorkspace(t *testing.T) {
252253
"-refresh",
253254
"-no-color",
254255
"-out",
255-
"/path/workspace.tfplan",
256+
"\"/path/workspace.tfplan\"",
256257
"-var",
257258
"atlantis_user=username",
258259
"-var",
@@ -306,7 +307,7 @@ func TestRun_NoWorkspaceSwitchIfNotNecessary(t *testing.T) {
306307
"-refresh",
307308
"-no-color",
308309
"-out",
309-
"/path/workspace.tfplan",
310+
"\"/path/workspace.tfplan\"",
310311
"-var",
311312
"atlantis_user=username",
312313
"-var",
@@ -368,7 +369,7 @@ func TestRun_AddsEnvVarFile(t *testing.T) {
368369
"-refresh",
369370
"-no-color",
370371
"-out",
371-
filepath.Join(tmpDir, "workspace.tfplan"),
372+
fmt.Sprintf("%q", filepath.Join(tmpDir, "workspace.tfplan")),
372373
"-var",
373374
"atlantis_user=username",
374375
"-var",
@@ -423,7 +424,7 @@ func TestRun_UsesDiffPathForProject(t *testing.T) {
423424
"-refresh",
424425
"-no-color",
425426
"-out",
426-
"/path/projectname-default.tfplan",
427+
"\"/path/projectname-default.tfplan\"",
427428
"-var",
428429
"atlantis_user=username",
429430
"-var",

0 commit comments

Comments
 (0)