From 93bfcff61af0ad5af41569e478929f0ed5bf4f05 Mon Sep 17 00:00:00 2001 From: Barrett Clark Date: Mon, 18 Oct 2021 16:02:45 -0500 Subject: [PATCH] More Terraform Cloud UX changes * Update e2e tests to specify Terraform Cloud * Update more of the terraform command flow to specify Terraform Cloud --- .../e2e/migrate_state_multi_to_tfc_test.go | 8 ++++---- ...migrate_state_remote_backend_to_tfc_test.go | 8 ++++---- .../e2e/migrate_state_single_to_tfc_test.go | 8 ++++---- internal/command/meta_backend.go | 18 +++++++++++++++--- internal/command/meta_backend_migrate.go | 13 ++++++++----- 5 files changed, 35 insertions(+), 20 deletions(-) diff --git a/internal/cloud/e2e/migrate_state_multi_to_tfc_test.go b/internal/cloud/e2e/migrate_state_multi_to_tfc_test.go index dd3ae2c26..e72169186 100644 --- a/internal/cloud/e2e/migrate_state_multi_to_tfc_test.go +++ b/internal/cloud/e2e/migrate_state_multi_to_tfc_test.go @@ -68,7 +68,7 @@ func Test_migrate_multi_to_tfc_cloud_name_strategy(t *testing.T) { userInput: []string{"yes", "yes"}, postInputOutput: []string{ `Do you want to copy existing state to the new backend?`, - `Successfully configured the backend "cloud"!`}, + `Successfully configured Terraform Cloud!`}, }, { command: []string{"workspace", "show"}, @@ -139,7 +139,7 @@ func Test_migrate_multi_to_tfc_cloud_name_strategy(t *testing.T) { userInput: []string{"yes", "yes"}, postInputOutput: []string{ `Do you want to copy existing state to the new backend?`, - `Successfully configured the backend "cloud"!`}, + `Successfully configured Terraform Cloud!`}, }, { command: []string{"workspace", "list"}, @@ -191,7 +191,7 @@ func Test_migrate_multi_to_tfc_cloud_name_strategy(t *testing.T) { op.prep(t, organization.Name, tf.WorkDir()) for _, tfCmd := range op.commands { t.Log("Running commands: ", tfCmd.command) - tfCmd.command = append(tfCmd.command, "-ignore-remote-version") + tfCmd.command = append(tfCmd.command) cmd := tf.Cmd(tfCmd.command...) cmd.Stdin = exp.Tty() cmd.Stdout = exp.Tty() @@ -303,7 +303,7 @@ func Test_migrate_multi_to_tfc_cloud_tags_strategy(t *testing.T) { commands: []tfCommand{ { command: []string{"init", "-migrate-state"}, - expectedCmdOutput: `The "cloud" backend configuration only allows named workspaces!`, + expectedCmdOutput: `Terraform Cloud configuration only allows named workspaces!`, userInput: []string{"dev", "1", "app-*", "1"}, postInputOutput: []string{ `Would you like to rename your workspaces?`, diff --git a/internal/cloud/e2e/migrate_state_remote_backend_to_tfc_test.go b/internal/cloud/e2e/migrate_state_remote_backend_to_tfc_test.go index 33c1686c8..0cb7d5efc 100644 --- a/internal/cloud/e2e/migrate_state_remote_backend_to_tfc_test.go +++ b/internal/cloud/e2e/migrate_state_remote_backend_to_tfc_test.go @@ -52,7 +52,7 @@ func Test_migrate_remote_backend_name_to_tfc_name(t *testing.T) { command: []string{"init", "-migrate-state", "-ignore-remote-version"}, expectedCmdOutput: `Do you want to copy existing state to the new backend?`, userInput: []string{"yes"}, - postInputOutput: []string{`Successfully configured the backend "cloud"!`}, + postInputOutput: []string{`Successfully configured Terraform Cloud!`}, }, { command: []string{"workspace", "show"}, @@ -234,7 +234,7 @@ func Test_migrate_remote_backend_name_to_tfc_name_different_org(t *testing.T) { command: []string{"init", "-migrate-state", "-ignore-remote-version"}, expectedCmdOutput: `Do you want to copy existing state to the new backend?`, userInput: []string{"yes"}, - postInputOutput: []string{`Successfully configured the backend "cloud"!`}, + postInputOutput: []string{`Successfully configured Terraform Cloud!`}, }, { command: []string{"workspace", "show"}, @@ -373,7 +373,7 @@ func Test_migrate_remote_backend_name_to_tfc_tags(t *testing.T) { commands: []tfCommand{ { command: []string{"init", "-migrate-state", "-ignore-remote-version"}, - expectedCmdOutput: `The "cloud" backend configuration only allows named workspaces!`, + expectedCmdOutput: `Terraform Cloud configuration only allows named workspaces!`, userInput: []string{"cloud-workspace", "yes"}, postInputOutput: []string{ `Do you want to copy existing state to the new backend?`, @@ -516,7 +516,7 @@ func Test_migrate_remote_backend_prefix_to_tfc_name(t *testing.T) { expectedCmdOutput: `Do you want to copy existing state to the new backend?`, userInput: []string{"yes"}, postInputOutput: []string{ - `Successfully configured the backend "cloud"!`}, + `Successfully configured Terraform Cloud!`}, }, { command: []string{"workspace", "show"}, diff --git a/internal/cloud/e2e/migrate_state_single_to_tfc_test.go b/internal/cloud/e2e/migrate_state_single_to_tfc_test.go index ebe85d1b5..805a5766d 100644 --- a/internal/cloud/e2e/migrate_state_single_to_tfc_test.go +++ b/internal/cloud/e2e/migrate_state_single_to_tfc_test.go @@ -51,9 +51,9 @@ func Test_migrate_single_to_tfc(t *testing.T) { commands: []tfCommand{ { command: []string{"init", "-migrate-state"}, - expectedCmdOutput: `Do you want to copy existing state to the new backend?`, + expectedCmdOutput: `Do you want to copy existing state to the Terraform Cloud?`, userInput: []string{"yes"}, - postInputOutput: []string{`Successfully configured the backend "cloud"!`}, + postInputOutput: []string{`Successfully configured Terraform Cloud!`}, }, { command: []string{"workspace", "list"}, @@ -102,9 +102,9 @@ func Test_migrate_single_to_tfc(t *testing.T) { commands: []tfCommand{ { command: []string{"init", "-migrate-state"}, - expectedCmdOutput: `The "cloud" backend configuration only allows named workspaces!`, + expectedCmdOutput: `Terraform Cloud configuration only allows named workspaces!`, userInput: []string{"new-workspace", "yes"}, - postInputOutput: []string{`Successfully configured the backend "cloud"!`}, + postInputOutput: []string{`Successfully configured Terraform Cloud!`}, }, { command: []string{"workspace", "list"}, diff --git a/internal/command/meta_backend.go b/internal/command/meta_backend.go index f3a2c11e2..94b9e5e5c 100644 --- a/internal/command/meta_backend.go +++ b/internal/command/meta_backend.go @@ -952,7 +952,11 @@ func (m *Meta) backend_C_r_S_changed(c *configs.Backend, cHash int, sMgr *clista // no need to confuse the user if the backend types are the same if s.Backend.Type != c.Type { - m.Ui.Output(strings.TrimSpace(fmt.Sprintf(outputBackendMigrateChange, s.Backend.Type, c.Type))) + output := fmt.Sprintf(outputBackendMigrateChange, s.Backend.Type, c.Type) + if c.Type == "cloud" { + output = fmt.Sprintf(outputBackendMigrateChangeCloud, s.Backend.Type) + } + m.Ui.Output(strings.TrimSpace(output)) } // Grab the existing backend @@ -1011,8 +1015,12 @@ func (m *Meta) backend_C_r_S_changed(c *configs.Backend, cHash int, sMgr *clista } if output { - 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 @@ -1306,6 +1314,10 @@ const outputBackendMigrateChange = ` Terraform detected that the backend type changed from %q to %q. ` +const outputBackendMigrateChangeCloud = ` +Terraform detected that the backend type changed from %q to Terraform Cloud. +` + const outputBackendMigrateLocal = ` Terraform has detected you're unconfiguring your previously set %q backend. ` diff --git a/internal/command/meta_backend_migrate.go b/internal/command/meta_backend_migrate.go index 08ec3b8e7..92eadfa03 100644 --- a/internal/command/meta_backend_migrate.go +++ b/internal/command/meta_backend_migrate.go @@ -686,12 +686,15 @@ func (m *Meta) promptMultiToSingleCloudMigration(opts *backendMigrateOpts) error } func (m *Meta) promptNewWorkspaceName(destinationType string) (string, error) { + message := fmt.Sprintf("[reset][bold][yellow]The %q backend configuration only allows "+ + "named workspaces![reset]", destinationType) + if destinationType == "cloud" { + message = fmt.Sprintf("[reset][bold][yellow]The Terraform Cloud configuration only allows " + + "named workspaces![reset]") + } name, err := m.UIInput().Input(context.Background(), &terraform.InputOpts{ - Id: "new-state-name", - Query: fmt.Sprintf( - "[reset][bold][yellow]The %q backend configuration only allows "+ - "named workspaces![reset]", - destinationType), + Id: "new-state-name", + Query: message, Description: strings.TrimSpace(inputBackendNewWorkspaceName), }) if err != nil {