mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-02-27 11:02:51 -05:00
The enhanced backends (local and remote) need to be able to render diagnostics during operations. Prior to this commit, this functionality was supported with a per-backend `ShowDiagnostics` function pointer. In order to allow users of these backends to control how diagnostics are rendered, this commit moves that function pointer to the `Operation` type. This means that a diagnostic renderer is configured for each operation, rather than once per backend initialization. Some secondary consequences of this change: - The `ReportResult` method on the backend is now moved to the `Operation` type, as it needs to access the `ShowDiagnostics` callback (and nothing else from the backend); - Tests which assumed that diagnostics would be written to the backend's `cli.Ui` instance are migrated to using a new record/playback diags helper function; - Apply, plan, and refresh commands now pass a pointer to the `Meta` struct's `showDiagnostics` method. This commit should not change how Terraform works, and is refactoring in preparation for more changes which move UI code out of the backend.
21 lines
364 B
Go
21 lines
364 B
Go
package remote
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform/backend"
|
|
)
|
|
|
|
// CLIInit implements backend.CLI
|
|
func (b *Remote) CLIInit(opts *backend.CLIOpts) error {
|
|
if cli, ok := b.local.(backend.CLI); ok {
|
|
if err := cli.CLIInit(opts); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
b.CLI = opts.CLI
|
|
b.CLIColor = opts.CLIColor
|
|
b.ContextOpts = opts.ContextOpts
|
|
|
|
return nil
|
|
}
|