From f8256f6634c8de055669bac3e06cd507146f895a Mon Sep 17 00:00:00 2001 From: Chris Arcand Date: Wed, 13 Oct 2021 10:22:12 -0500 Subject: [PATCH] Update ux for "terraform init [-reconfigure]" --- internal/command/init.go | 30 ++++++++++++++++++++++++++++-- internal/command/meta_backend.go | 10 +++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/internal/command/init.go b/internal/command/init.go index d88ec181e..3de1d4101 100644 --- a/internal/command/init.go +++ b/internal/command/init.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/terraform/internal/addrs" "github.com/hashicorp/terraform/internal/backend" backendInit "github.com/hashicorp/terraform/internal/backend/init" + "github.com/hashicorp/terraform/internal/cloud" "github.com/hashicorp/terraform/internal/configs" "github.com/hashicorp/terraform/internal/configs/configschema" "github.com/hashicorp/terraform/internal/getproviders" @@ -304,12 +305,25 @@ func (c *InitCommand) Run(args []string) int { // by errors then we'll output them here so that the success message is // still the final thing shown. c.showDiagnostics(diags) - c.Ui.Output(c.Colorize().Color(strings.TrimSpace(outputInitSuccess))) + _, cloud := back.(*cloud.Cloud) + output := "" + if cloud { + output = outputInitSuccessCloud + } else { + output = outputInitSuccess + } + + c.Ui.Output(c.Colorize().Color(strings.TrimSpace(output))) + if !c.RunningInAutomation { // If we're not running in an automation wrapper, give the user // some more detailed next steps that are appropriate for interactive // shell usage. - c.Ui.Output(c.Colorize().Color(strings.TrimSpace(outputInitSuccessCLI))) + output = outputInitSuccessCLI + if cloud { + output = outputInitSuccessCLICloud + } + c.Ui.Output(c.Colorize().Color(strings.TrimSpace(output))) } return 0 } @@ -1087,6 +1101,10 @@ const outputInitSuccess = ` [reset][bold][green]Terraform has been successfully initialized![reset][green] ` +const outputInitSuccessCloud = ` +[reset][bold][green]Terraform Cloud has been successfully initialized![reset][green] +` + const outputInitSuccessCLI = `[reset][green] You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands @@ -1097,6 +1115,14 @@ rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary. ` +const outputInitSuccessCLICloud = `[reset][green] +You may now begin working with Terraform Cloud. Try running "terraform plan" to +see any changes that are required for your infrastructure. + +If you ever set or change modules or configuration for Terraform, run +"terraform init" again to reinitialize your working directory. +` + // providerProtocolTooOld is a message sent to the CLI UI if the provider's // supported protocol versions are too old for the user's version of terraform, // but a newer version of the provider is compatible. diff --git a/internal/command/meta_backend.go b/internal/command/meta_backend.go index 58cafdd4f..f3a2c11e2 100644 --- a/internal/command/meta_backend.go +++ b/internal/command/meta_backend.go @@ -17,6 +17,7 @@ import ( "github.com/hashicorp/hcl/v2" "github.com/hashicorp/hcl/v2/hcldec" "github.com/hashicorp/terraform/internal/backend" + "github.com/hashicorp/terraform/internal/cloud" "github.com/hashicorp/terraform/internal/command/arguments" "github.com/hashicorp/terraform/internal/command/clistate" "github.com/hashicorp/terraform/internal/command/views" @@ -921,9 +922,12 @@ func (m *Meta) backend_C_r_s(c *configs.Backend, cHash int, sMgr *clistate.Local return nil, diags } - // By now the backend is successfully configured. - m.Ui.Output(m.Colorize().Color(fmt.Sprintf( - "[reset][green]\n"+strings.TrimSpace(successBackendSet), s.Backend.Type))) + // By now the backend is successfully configured. If using Terraform Cloud, the success + // message is handled as part of the final init message + if _, ok := b.(*cloud.Cloud); !ok { + m.Ui.Output(m.Colorize().Color(fmt.Sprintf( + "[reset][green]\n"+strings.TrimSpace(successBackendSet), s.Backend.Type))) + } return b, diags }