diff --git a/backend/remote/backend_plan.go b/backend/remote/backend_plan.go index 9e73587ac186..ca49ae24b5b0 100644 --- a/backend/remote/backend_plan.go +++ b/backend/remote/backend_plan.go @@ -152,6 +152,25 @@ func (b *Remote) plan(stopCtx, cancelCtx context.Context, op *backend.Operation, filepath.Clean(configDir), filepath.Clean(w.WorkingDirectory), )) + + // If the workspace has a subdirectory as its working directory then + // our configDir will be some parent directory of the current working + // directory. Users are likely to find that surprising, so we'll + // produce an explicit message about it to be transparent about what + // we are doing and why. + if w.WorkingDirectory != "" && filepath.Base(configDir) != w.WorkingDirectory { + if b.CLI != nil { + b.CLI.Output(fmt.Sprintf(strings.TrimSpace(` +The remote workspace is configured to work with configuration at +%s relative to the target repository. + +Therefore Terraform will upload the full contents of the following directory +to capture the filesystem context the remote workspace expects: + %s +`), w.WorkingDirectory, configDir) + "\n") + } + } + } else { // We did a check earlier to make sure we either have a config dir, // or the plan is run with -destroy. So this else clause will only diff --git a/backend/remote/backend_plan_test.go b/backend/remote/backend_plan_test.go index f3ae3bb8358d..6b3d967530c4 100644 --- a/backend/remote/backend_plan_test.go +++ b/backend/remote/backend_plan_test.go @@ -647,6 +647,9 @@ func TestRemote_planWithWorkingDirectory(t *testing.T) { } output := b.CLI.(*cli.MockUi).OutputWriter.String() + if !strings.Contains(output, "The remote workspace is configured to work with configuration") { + t.Fatalf("expected working directory warning: %s", output) + } if !strings.Contains(output, "Running plan in the remote backend") { t.Fatalf("expected remote backend header in output: %s", output) }