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()),