From 8a3f4e903b2d0b430cd75dd8f8264786bcb870ac Mon Sep 17 00:00:00 2001 From: CJ Horton Date: Wed, 31 May 2023 11:51:39 -0700 Subject: [PATCH] generating configuration is not allowed with the remote backend --- internal/backend/remote/backend_plan.go | 9 ++++++ internal/backend/remote/backend_plan_test.go | 30 ++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/internal/backend/remote/backend_plan.go b/internal/backend/remote/backend_plan.go index 79ba3088dd..40c5c080bb 100644 --- a/internal/backend/remote/backend_plan.go +++ b/internal/backend/remote/backend_plan.go @@ -69,6 +69,15 @@ func (b *Remote) opPlan(stopCtx, cancelCtx context.Context, op *backend.Operatio )) } + if op.GenerateConfigOut != "" { + diags = diags.Append(tfdiags.Sourceless( + tfdiags.Error, + "Generating configuration is not currently supported", + `The "remote" backend does not currently support generating resource configuration `+ + `as part of a plan.`, + )) + } + if b.hasExplicitVariableValues(op) { diags = diags.Append(tfdiags.Sourceless( tfdiags.Error, diff --git a/internal/backend/remote/backend_plan_test.go b/internal/backend/remote/backend_plan_test.go index 7aba624b27..90684923fa 100644 --- a/internal/backend/remote/backend_plan_test.go +++ b/internal/backend/remote/backend_plan_test.go @@ -1248,3 +1248,33 @@ func TestRemote_planOtherError(t *testing.T) { t.Fatalf("expected error message, got: %s", err.Error()) } } + +func TestRemote_planWithGenConfigOut(t *testing.T) { + b, bCleanup := testBackendDefault(t) + defer bCleanup() + + op, configCleanup, done := testOperationPlan(t, "./testdata/plan") + defer configCleanup() + + op.GenerateConfigOut = "generated.tf" + op.Workspace = backend.DefaultStateName + + run, err := b.Operation(context.Background(), op) + if err != nil { + t.Fatalf("error starting operation: %v", err) + } + + <-run.Done() + output := done(t) + if run.Result == backend.OperationSuccess { + t.Fatal("expected plan operation to fail") + } + if !run.PlanEmpty { + t.Fatalf("expected plan to be empty") + } + + errOutput := output.Stderr() + if !strings.Contains(errOutput, "Generating configuration is not currently supported") { + t.Fatalf("expected error about config generation, got: %v", errOutput) + } +}