cloud: Initialize a new cloud view in the backend to render messages based on view type.

Signed-off-by: Bruno Schaatsbergen <git@bschaatsbergen.com>
pull/35929/head
Bruno Schaatsbergen 1 year ago
parent c021638507
commit d8bfe7a80b
No known key found for this signature in database

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

@ -65,8 +65,7 @@ type Cloud struct {
// client is the HCP Terraform or Terraform Enterprise API client.
client *tfe.Client
//FIXME: something
View *views.View
View views.Cloud
// Hostname of HCP Terraform or Terraform Enterprise
Hostname string
@ -606,10 +605,7 @@ func cliConfigToken(hostname svchost.Hostname, services *disco.Disco) (string, e
// backend to log any connection issues to prevent data loss.
func (b *Cloud) retryLogHook(attemptNum int, resp *http.Response) {
if b.CLI != nil {
h := views.NewRetryLoghook(b.View)
if output := h.RetryLogHook(attemptNum, resp, true); len(output) > 0 {
b.CLI.Output(b.Colorize().Color(output))
}
b.View.RetryLog(attemptNum, resp)
}
}

@ -6,6 +6,7 @@ package cloud
import (
"github.com/hashicorp/terraform/internal/backend/backendrun"
"github.com/hashicorp/terraform/internal/command/jsonformat"
"github.com/hashicorp/terraform/internal/command/views"
)
// CLIInit implements backendrun.CLI
@ -25,8 +26,8 @@ func (b *Cloud) CLIInit(opts *backendrun.CLIOpts) error {
Streams: opts.Streams,
Colorize: opts.CLIColor,
}
//FIXME: something
b.View = opts.View
view := views.NewView(opts.Streams)
b.View = views.NewCloud(opts.ViewType, view)
return nil
}

@ -151,6 +151,11 @@ func (m *Meta) Backend(opts *BackendOpts) (backendrun.OperationsBackend, tfdiags
}
cliOpts.Validation = true
// FIXME: Temporarily exposing ViewType to the backend.
// This is a workaround until the backend is refactored to support
// native View handling.
cliOpts.ViewType = opts.ViewType
// If the backend supports CLI initialization, do it.
if cli, ok := b.(backendrun.CLI); ok {
if err := cli.CLIInit(cliOpts); err != nil {
@ -386,11 +391,9 @@ func (m *Meta) backendCLIOpts() (*backendrun.CLIOpts, error) {
return nil, err
}
return &backendrun.CLIOpts{
CLI: m.Ui,
CLIColor: m.Colorize(),
Streams: m.Streams,
//FIXME: something
View: views.NewView(m.Streams),
CLI: m.Ui,
CLIColor: m.Colorize(),
Streams: m.Streams,
StatePath: m.statePath,
StateOutPath: m.stateOutPath,
StateBackupPath: m.backupPath,

Loading…
Cancel
Save