From ee913a1c872c1f8dbb42f11b7513b446af9b49c1 Mon Sep 17 00:00:00 2001 From: Masayuki Morita Date: Tue, 9 Jun 2020 02:36:19 +0900 Subject: [PATCH] command/0.13upgrade: make confirmation more user-friendly (#25142) I feel the current confirmation prompt for 0.13upgrade command is ambiguous what is expected. Actually, when I used it for the first time, I cancelled it by typing `y` instead of `yes`. I believe it would be great if the 0.13upgrade command tell us the expected value for confirmation like 0.12upgrade. --- command/013_config_upgrade.go | 8 +++++++- command/013_config_upgrade_test.go | 13 ++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/command/013_config_upgrade.go b/command/013_config_upgrade.go index 8786cb91b..32e830051 100644 --- a/command/013_config_upgrade.go +++ b/command/013_config_upgrade.go @@ -1,6 +1,7 @@ package command import ( + "context" "fmt" "io/ioutil" "os" @@ -14,6 +15,7 @@ import ( "github.com/hashicorp/terraform/addrs" "github.com/hashicorp/terraform/configs" "github.com/hashicorp/terraform/internal/getproviders" + "github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/tfdiags" tfversion "github.com/hashicorp/terraform/version" "github.com/zclconf/go-cty/cty" @@ -148,7 +150,11 @@ command and dealing with them before running this command again. if dir != "." { query = fmt.Sprintf("Would you like to upgrade the module in %s?", dir) } - v, err := c.Ui.Ask(query) + v, err := c.UIInput().Input(context.Background(), &terraform.InputOpts{ + Id: "approve", + Query: query, + Description: `Only 'yes' will be accepted to confirm.`, + }) if err != nil { diags = diags.Append(err) c.showDiagnostics(diags) diff --git a/command/013_config_upgrade_test.go b/command/013_config_upgrade_test.go index 7eab57451..d2e9b9a41 100644 --- a/command/013_config_upgrade_test.go +++ b/command/013_config_upgrade_test.go @@ -1,7 +1,6 @@ package command import ( - "bytes" "io/ioutil" "os" "path" @@ -215,10 +214,10 @@ func TestZeroThirteenUpgrade_confirm(t *testing.T) { defer os.RemoveAll(td) defer testChdir(t, td)() + // Ask input + defer testInteractiveInput(t, []string{"yes"})() + ui := new(cli.MockUi) - inputBuf := &bytes.Buffer{} - ui.InputReader = inputBuf - inputBuf.WriteString("yes") c := &ZeroThirteenUpgradeCommand{ Meta: Meta{ testingOverrides: metaOverridesForProvider(testProvider()), @@ -244,10 +243,10 @@ func TestZeroThirteenUpgrade_cancel(t *testing.T) { defer os.RemoveAll(td) defer testChdir(t, td)() + // Ask input + defer testInteractiveInput(t, []string{"no"})() + ui := new(cli.MockUi) - inputBuf := &bytes.Buffer{} - ui.InputReader = inputBuf - inputBuf.WriteString("no") c := &ZeroThirteenUpgradeCommand{ Meta: Meta{ testingOverrides: metaOverridesForProvider(testProvider()),