backend/cloud: expose View to enable reuse in a (cloud) backend

Signed-off-by: Bruno Schaatsbergen <git@bschaatsbergen.com>
This commit is contained in:
Bruno Schaatsbergen 2024-11-08 13:51:06 -06:00
parent 94c732b7a5
commit f1428b3388
No known key found for this signature in database
3 changed files with 6 additions and 4 deletions

View file

@ -9,6 +9,7 @@ import (
"github.com/hashicorp/terraform/internal/backend"
"github.com/hashicorp/terraform/internal/command/arguments"
"github.com/hashicorp/terraform/internal/command/views"
"github.com/hashicorp/terraform/internal/terminal"
"github.com/hashicorp/terraform/internal/terraform"
)
@ -61,10 +62,11 @@ type CLIOpts struct {
// for tailoring the output to fit the attached terminal, for example.
Streams *terminal.Streams
// FIXME: Temporarily exposing ViewType to the backend.
// FIXME: Temporarily exposing ViewType and View to the backend.
// This is a workaround until the backend is refactored to support
// native View handling.
ViewType arguments.ViewType
View *views.View
// StatePath is the local path where state is read from.
//

View file

@ -26,8 +26,7 @@ func (b *Cloud) CLIInit(opts *backendrun.CLIOpts) error {
Streams: opts.Streams,
Colorize: opts.CLIColor,
}
view := views.NewView(opts.Streams)
b.View = views.NewCloud(opts.ViewType, view)
b.View = views.NewCloud(opts.ViewType, opts.View)
return nil
}

View file

@ -151,10 +151,11 @@ func (m *Meta) Backend(opts *BackendOpts) (backendrun.OperationsBackend, tfdiags
}
cliOpts.Validation = true
// FIXME: Temporarily exposing ViewType to the backend.
// FIXME: Temporarily exposing ViewType and View to the backend.
// This is a workaround until the backend is refactored to support
// native View handling.
cliOpts.ViewType = opts.ViewType
cliOpts.View = m.View
// If the backend supports CLI initialization, do it.
if cli, ok := b.(backendrun.CLI); ok {