More Terraform Cloud UX changes

* Update e2e tests to specify Terraform Cloud
* Update more of the terraform command flow to specify Terraform Cloud
This commit is contained in:
Barrett Clark 2021-10-18 16:02:45 -05:00 committed by Chris Arcand
parent 261a2b49d3
commit 93bfcff61a
5 changed files with 35 additions and 20 deletions

View File

@ -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?`,

View File

@ -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"},

View File

@ -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"},

View File

@ -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.
`

View File

@ -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 {