diff --git a/internal/backend/backendrun/cli.go b/internal/backend/backendrun/cli.go index 01fd90b0d0..eeae51ae28 100644 --- a/internal/backend/backendrun/cli.go +++ b/internal/backend/backendrun/cli.go @@ -8,6 +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/terminal" "github.com/hashicorp/terraform/internal/terraform" ) @@ -60,6 +61,9 @@ type CLIOpts struct { // for tailoring the output to fit the attached terminal, for example. Streams *terminal.Streams + //FIXME: something + View *views.View + // StatePath is the local path where state is read from. // // StateOutPath is the local path where the state will be written. diff --git a/internal/cloud/backend.go b/internal/cloud/backend.go index 9d20de7755..f9ea25f395 100644 --- a/internal/cloud/backend.go +++ b/internal/cloud/backend.go @@ -65,9 +65,8 @@ type Cloud struct { // client is the HCP Terraform or Terraform Enterprise API client. client *tfe.Client - // viewHooks implements functions integrating the tfe.Client with the CLI - // output. - viewHooks views.CloudHooks + //FIXME: something + View *views.View // Hostname of HCP Terraform or Terraform Enterprise Hostname string @@ -607,7 +606,8 @@ 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 { - if output := b.viewHooks.RetryLogHook(attemptNum, resp, true); len(output) > 0 { + retryLogHook := views.NewRetryLoghook(b.View) + if output := retryLogHook.RetryLogHook(attemptNum, resp, true); len(output) > 0 { b.CLI.Output(b.Colorize().Color(output)) } } diff --git a/internal/cloud/backend_cli.go b/internal/cloud/backend_cli.go index c63746ec03..5d5bf1f98c 100644 --- a/internal/cloud/backend_cli.go +++ b/internal/cloud/backend_cli.go @@ -25,6 +25,8 @@ func (b *Cloud) CLIInit(opts *backendrun.CLIOpts) error { Streams: opts.Streams, Colorize: opts.CLIColor, } + //FIXME: something + b.View = opts.View return nil } diff --git a/internal/command/meta_backend.go b/internal/command/meta_backend.go index de9c877282..9337b754eb 100644 --- a/internal/command/meta_backend.go +++ b/internal/command/meta_backend.go @@ -386,9 +386,11 @@ func (m *Meta) backendCLIOpts() (*backendrun.CLIOpts, error) { return nil, err } return &backendrun.CLIOpts{ - CLI: m.Ui, - CLIColor: m.Colorize(), - Streams: m.Streams, + CLI: m.Ui, + CLIColor: m.Colorize(), + Streams: m.Streams, + //FIXME: something + View: views.NewView(m.Streams), StatePath: m.statePath, StateOutPath: m.stateOutPath, StateBackupPath: m.backupPath, diff --git a/internal/command/views/hook_cloud.go b/internal/command/views/hook_retry_log.go similarity index 80% rename from internal/command/views/hook_cloud.go rename to internal/command/views/hook_retry_log.go index a9130d29d9..fa1df2fcc4 100644 --- a/internal/command/views/hook_cloud.go +++ b/internal/command/views/hook_retry_log.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package views import ( @@ -30,7 +33,7 @@ func NewRetryLoghook(view *View) *RetryLogHook { // // If colorize is true, then the value returned by this function should be // processed by a colorizer. -func (hooks *RetryLogHook) RetryLogHook(attemptNum int, resp *http.Response, colorize bool) string { +func (hook *RetryLogHook) RetryLogHook(attemptNum int, resp *http.Response, colorize bool) string { // Ignore the first retry to make sure any delayed output will // be written to the console before we start logging retries. // @@ -38,7 +41,7 @@ func (hooks *RetryLogHook) RetryLogHook(attemptNum int, resp *http.Response, col // requests and server errors, but in the cloud backend we only // care about server errors so we ignore rate limit (429) errors. if attemptNum == 0 || (resp != nil && resp.StatusCode == 429) { - hooks.lastRetry = time.Now() + hook.lastRetry = time.Now() return "" } @@ -46,13 +49,13 @@ func (hooks *RetryLogHook) RetryLogHook(attemptNum int, resp *http.Response, col if attemptNum == 1 { msg = initialRetryError } else { - msg = fmt.Sprintf(repeatedRetryError, time.Since(hooks.lastRetry).Round(time.Second)) + msg = fmt.Sprintf(repeatedRetryError, time.Since(hook.lastRetry).Round(time.Second)) } if colorize { return strings.TrimSpace(fmt.Sprintf("[reset][yellow]%s[reset]", msg)) } - return hooks.view.colorize.Color(strings.TrimSpace(msg)) + return hook.view.colorize.Color(strings.TrimSpace(msg)) } // The newline in this error is to make it look good in the CLI! diff --git a/internal/command/views/test.go b/internal/command/views/test.go index 2fbb85a563..5c363ede38 100644 --- a/internal/command/views/test.go +++ b/internal/command/views/test.go @@ -101,7 +101,7 @@ func NewTest(vt arguments.ViewType, view *View) Test { } type TestHuman struct { - CloudHooks + RetryLogHook view *View } @@ -371,11 +371,11 @@ func (t *TestHuman) TFCStatusUpdate(status tfe.TestRunStatus, elapsed time.Durat } func (t *TestHuman) TFCRetryHook(attemptNum int, resp *http.Response) { - t.view.streams.Println(t.view.colorize.Color(t.RetryLogHook(attemptNum, resp, true))) + t.view.streams.Println(t.view.colorize.Color(t.RetryLogHook.RetryLogHook(attemptNum, resp, true))) } type TestJSON struct { - CloudHooks + RetryLogHook view *JSONView } @@ -730,7 +730,7 @@ func (t *TestJSON) TFCStatusUpdate(status tfe.TestRunStatus, elapsed time.Durati func (t *TestJSON) TFCRetryHook(attemptNum int, resp *http.Response) { t.view.log.Error( - t.RetryLogHook(attemptNum, resp, false), + t.RetryLogHook.RetryLogHook(attemptNum, resp, false), "type", json.MessageTestRetry, ) }