From d8bfe7a80b378bf6ebdaaa194a68d217eba3e4d9 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Fri, 1 Nov 2024 16:18:26 +0100 Subject: [PATCH] cloud: Initialize a new cloud view in the backend to render messages based on view type. Signed-off-by: Bruno Schaatsbergen --- internal/backend/backendrun/cli.go | 8 +++++--- internal/cloud/backend.go | 8 ++------ internal/cloud/backend_cli.go | 5 +++-- internal/command/meta_backend.go | 13 ++++++++----- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/internal/backend/backendrun/cli.go b/internal/backend/backendrun/cli.go index eeae51ae28..c731ef4f5e 100644 --- a/internal/backend/backendrun/cli.go +++ b/internal/backend/backendrun/cli.go @@ -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. // diff --git a/internal/cloud/backend.go b/internal/cloud/backend.go index 8d7f43b859..6595c84ac7 100644 --- a/internal/cloud/backend.go +++ b/internal/cloud/backend.go @@ -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) } } diff --git a/internal/cloud/backend_cli.go b/internal/cloud/backend_cli.go index 5d5bf1f98c..60edc2711b 100644 --- a/internal/cloud/backend_cli.go +++ b/internal/cloud/backend_cli.go @@ -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 } diff --git a/internal/command/meta_backend.go b/internal/command/meta_backend.go index 9337b754eb..65155be5ae 100644 --- a/internal/command/meta_backend.go +++ b/internal/command/meta_backend.go @@ -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,