diff --git a/backend/local/backend.go b/backend/local/backend.go index 4badd8961..b9b028d54 100644 --- a/backend/local/backend.go +++ b/backend/local/backend.go @@ -408,7 +408,15 @@ func (b *Local) ReportResult(op *backend.RunningOperation, diags tfdiags.Diagnos } else { op.Result = backend.OperationSuccess } - b.ShowDiagnostics(diags) + if b.ShowDiagnostics != nil { + b.ShowDiagnostics(diags) + } else { + // Shouldn't generally happen, but if it does then we'll at least + // make some noise in the logs to help us spot it. + if len(diags) != 0 { + log.Printf("[ERROR] Local backend needs to report diagnostics but ShowDiagnostics callback is not set: %s", diags.ErrWithWarnings()) + } + } } // Colorize returns the Colorize structure that can be used for colorizing diff --git a/command/meta_backend.go b/command/meta_backend.go index 0691d30bd..7596b45d5 100644 --- a/command/meta_backend.go +++ b/command/meta_backend.go @@ -159,6 +159,19 @@ func (m *Meta) BackendForPlan(settings plans.Backend) (backend.Enhanced, tfdiags configureDiags := b.Configure(configVal) diags = diags.Append(configureDiags) + // If the backend supports CLI initialization, do it. + if cli, ok := b.(backend.CLI); ok { + cliOpts := m.backendCLIOpts() + if err := cli.CLIInit(cliOpts); err != nil { + diags = diags.Append(fmt.Errorf( + "Error initializing backend %T: %s\n\n"+ + "This is a bug; please report it to the backend developer", + b, err, + )) + return nil, diags + } + } + // If the result of loading the backend is an enhanced backend, // then return that as-is. This works even if b == nil (it will be !ok). if enhanced, ok := b.(backend.Enhanced); ok {