mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
command/init: Be explicit that some options are not relevant for Cloud
There are a few command line options for "terraform init" which are only relevant when working with traditional backends, with the Cloud integration previously just mostly ignoring them, or sometimes misbehaving slightly due to them creating an unreasonable situation. Now we'll catch these and return explicit errors, in order to be clear that these options are not needed nor supported in Cloud mode.
This commit is contained in:
@@ -28,7 +28,7 @@ func Test_backend_apply_before_init(t *testing.T) {
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"apply"},
|
||||
expectedCmdOutput: `Terraform Cloud initialization required, please run "terraform init"`,
|
||||
expectedCmdOutput: `Terraform Cloud initialization required: please run "terraform init"`,
|
||||
expectError: true,
|
||||
},
|
||||
},
|
||||
@@ -62,7 +62,7 @@ func Test_backend_apply_before_init(t *testing.T) {
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"apply"},
|
||||
expectedCmdOutput: `Terraform Cloud initialization required, please run "terraform init"`,
|
||||
expectedCmdOutput: `Terraform Cloud initialization required: please run "terraform init"`,
|
||||
expectError: true,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -60,7 +60,7 @@ func Test_migrate_multi_to_tfc_cloud_name_strategy(t *testing.T) {
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state"},
|
||||
command: []string{"init"},
|
||||
expectedCmdOutput: `Do you want to copy only your current workspace?`,
|
||||
userInput: []string{"yes", "yes"},
|
||||
postInputOutput: []string{
|
||||
@@ -127,7 +127,7 @@ func Test_migrate_multi_to_tfc_cloud_name_strategy(t *testing.T) {
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state"},
|
||||
command: []string{"init"},
|
||||
expectedCmdOutput: `Do you want to copy only your current workspace?`,
|
||||
userInput: []string{"yes", "yes"},
|
||||
postInputOutput: []string{
|
||||
@@ -195,7 +195,7 @@ func Test_migrate_multi_to_tfc_cloud_name_strategy(t *testing.T) {
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state"},
|
||||
command: []string{"init"},
|
||||
expectedCmdOutput: `Do you want to copy only your current workspace?`,
|
||||
userInput: []string{"yes", "yes"},
|
||||
postInputOutput: []string{
|
||||
@@ -268,7 +268,6 @@ func Test_migrate_multi_to_tfc_cloud_name_strategy(t *testing.T) {
|
||||
if tfCmd.expectedCmdOutput != "" {
|
||||
got, err := exp.ExpectString(tfCmd.expectedCmdOutput)
|
||||
if err != nil {
|
||||
|
||||
t.Fatalf("error while waiting for output\nwant: %s\nerror: %s\noutput\n%s", tfCmd.expectedCmdOutput, err, got)
|
||||
}
|
||||
}
|
||||
@@ -365,7 +364,7 @@ func Test_migrate_multi_to_tfc_cloud_tags_strategy(t *testing.T) {
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state"},
|
||||
command: []string{"init"},
|
||||
expectedCmdOutput: `Terraform Cloud requires all workspaces to be given an explicit name.`,
|
||||
userInput: []string{"dev", "1", "app-*"},
|
||||
postInputOutput: []string{
|
||||
@@ -470,7 +469,7 @@ func Test_migrate_multi_to_tfc_cloud_tags_strategy(t *testing.T) {
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state"},
|
||||
command: []string{"init"},
|
||||
expectedCmdOutput: `Terraform Cloud requires all workspaces to be given an explicit name.`,
|
||||
userInput: []string{"dev", "1", "app-*"},
|
||||
postInputOutput: []string{
|
||||
|
||||
@@ -42,8 +42,8 @@ func Test_migrate_remote_backend_name_to_tfc_name(t *testing.T) {
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state", "-ignore-remote-version"},
|
||||
expectedCmdOutput: `Do you want to copy existing state to Terraform Cloud?`,
|
||||
command: []string{"init", "-ignore-remote-version"},
|
||||
expectedCmdOutput: `Should Terraform migrate your existing state?`,
|
||||
userInput: []string{"yes"},
|
||||
postInputOutput: []string{`Terraform Cloud has been successfully initialized!`},
|
||||
},
|
||||
@@ -163,7 +163,7 @@ func Test_migrate_remote_backend_name_to_tfc_same_name(t *testing.T) {
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state", "-ignore-remote-version"},
|
||||
command: []string{"init", "-ignore-remote-version"},
|
||||
expectedCmdOutput: `Terraform Cloud has been successfully initialized!`,
|
||||
},
|
||||
{
|
||||
@@ -283,8 +283,8 @@ func Test_migrate_remote_backend_name_to_tfc_name_different_org(t *testing.T) {
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state", "-ignore-remote-version"},
|
||||
expectedCmdOutput: `Do you want to copy existing state to Terraform Cloud?`,
|
||||
command: []string{"init", "-ignore-remote-version"},
|
||||
expectedCmdOutput: `Should Terraform migrate your existing state?`,
|
||||
userInput: []string{"yes"},
|
||||
postInputOutput: []string{`Terraform Cloud has been successfully initialized!`},
|
||||
},
|
||||
@@ -414,11 +414,11 @@ func Test_migrate_remote_backend_name_to_tfc_tags(t *testing.T) {
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state", "-ignore-remote-version"},
|
||||
command: []string{"init", "-ignore-remote-version"},
|
||||
expectedCmdOutput: `Terraform Cloud requires all workspaces to be given an explicit name.`,
|
||||
userInput: []string{"cloud-workspace", "yes"},
|
||||
postInputOutput: []string{
|
||||
`Do you want to copy existing state to Terraform Cloud?`,
|
||||
`Should Terraform migrate your existing state?`,
|
||||
`Terraform Cloud has been successfully initialized!`},
|
||||
},
|
||||
{
|
||||
@@ -544,8 +544,8 @@ func Test_migrate_remote_backend_prefix_to_tfc_name_strategy_single_workspace(t
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state", "-ignore-remote-version"},
|
||||
expectedCmdOutput: `Do you want to copy existing state to Terraform Cloud?`,
|
||||
command: []string{"init", "-ignore-remote-version"},
|
||||
expectedCmdOutput: `Should Terraform migrate your existing state?`,
|
||||
userInput: []string{"yes"},
|
||||
postInputOutput: []string{
|
||||
`Terraform Cloud has been successfully initialized!`},
|
||||
@@ -679,7 +679,7 @@ func Test_migrate_remote_backend_prefix_to_tfc_name_strategy_multi_workspace(t *
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state", "-ignore-remote-version"},
|
||||
command: []string{"init", "-ignore-remote-version"},
|
||||
expectedCmdOutput: `Do you want to copy only your current workspace?`,
|
||||
userInput: []string{"yes"},
|
||||
postInputOutput: []string{
|
||||
@@ -822,11 +822,11 @@ func Test_migrate_remote_backend_prefix_to_tfc_tags_strategy_single_workspace(t
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state", "-ignore-remote-version"},
|
||||
command: []string{"init", "-ignore-remote-version"},
|
||||
expectedCmdOutput: `Terraform Cloud requires all workspaces to be given an explicit name.`,
|
||||
userInput: []string{"cloud-workspace", "yes"},
|
||||
postInputOutput: []string{
|
||||
`Do you want to copy existing state to Terraform Cloud?`,
|
||||
`Should Terraform migrate your existing state?`,
|
||||
`Terraform Cloud has been successfully initialized!`},
|
||||
},
|
||||
{
|
||||
@@ -961,7 +961,7 @@ func Test_migrate_remote_backend_prefix_to_tfc_tags_strategy_multi_workspace(t *
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state", "-ignore-remote-version"},
|
||||
command: []string{"init", "-ignore-remote-version"},
|
||||
expectedCmdOutput: `Do you wish to proceed?`,
|
||||
userInput: []string{"yes"},
|
||||
postInputOutput: []string{`Terraform Cloud has been successfully initialized!`},
|
||||
|
||||
@@ -47,8 +47,8 @@ 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 Terraform Cloud?`,
|
||||
command: []string{"init"},
|
||||
expectedCmdOutput: `Should Terraform migrate your existing state?`,
|
||||
userInput: []string{"yes"},
|
||||
postInputOutput: []string{`Terraform Cloud has been successfully initialized!`},
|
||||
},
|
||||
@@ -96,11 +96,11 @@ func Test_migrate_single_to_tfc(t *testing.T) {
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state"},
|
||||
command: []string{"init"},
|
||||
expectedCmdOutput: `Terraform Cloud requires all workspaces to be given an explicit name.`,
|
||||
userInput: []string{"new-workspace", "yes"},
|
||||
postInputOutput: []string{
|
||||
`Do you want to copy existing state to Terraform Cloud?`,
|
||||
`Should Terraform migrate your existing state?`,
|
||||
`Terraform Cloud has been successfully initialized!`},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -36,7 +36,7 @@ func Test_migrate_tfc_to_other(t *testing.T) {
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state"},
|
||||
command: []string{"init"},
|
||||
expectedCmdOutput: `Migrating state from Terraform Cloud to another backend is not yet implemented.`,
|
||||
expectError: true,
|
||||
},
|
||||
|
||||
@@ -69,8 +69,8 @@ func Test_migrate_tfc_to_tfc_single_workspace(t *testing.T) {
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state", "-ignore-remote-version"},
|
||||
expectedCmdOutput: `Do you want to copy existing state to Terraform Cloud?`,
|
||||
command: []string{"init", "-ignore-remote-version"},
|
||||
expectedCmdOutput: `Should Terraform migrate your existing state?`,
|
||||
userInput: []string{"yes"},
|
||||
postInputOutput: []string{`Terraform Cloud has been successfully initialized!`},
|
||||
},
|
||||
@@ -127,11 +127,11 @@ func Test_migrate_tfc_to_tfc_single_workspace(t *testing.T) {
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state", "-ignore-remote-version"},
|
||||
command: []string{"init", "-ignore-remote-version"},
|
||||
expectedCmdOutput: `Terraform Cloud requires all workspaces to be given an explicit name.`,
|
||||
userInput: []string{"new-workspace", "yes"},
|
||||
postInputOutput: []string{
|
||||
`Do you want to copy existing state to Terraform Cloud?`,
|
||||
`Should Terraform migrate your existing state?`,
|
||||
`Terraform Cloud has been successfully initialized!`},
|
||||
},
|
||||
{
|
||||
@@ -196,7 +196,7 @@ func Test_migrate_tfc_to_tfc_single_workspace(t *testing.T) {
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state"},
|
||||
command: []string{"init"},
|
||||
expectedCmdOutput: `Terraform Cloud requires all workspaces to be given an explicit name.`,
|
||||
expectError: true,
|
||||
userInput: []string{"new-workspace", "yes"},
|
||||
@@ -367,11 +367,11 @@ func Test_migrate_tfc_to_tfc_multiple_workspace(t *testing.T) {
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state", "-ignore-remote-version"},
|
||||
command: []string{"init", "-ignore-remote-version"},
|
||||
expectedCmdOutput: `Do you want to copy only your current workspace?`,
|
||||
userInput: []string{"yes", "yes"},
|
||||
postInputOutput: []string{
|
||||
`Do you want to copy existing state to Terraform Cloud?`,
|
||||
`Should Terraform migrate your existing state?`,
|
||||
`Terraform Cloud has been successfully initialized!`},
|
||||
},
|
||||
{
|
||||
@@ -446,7 +446,7 @@ func Test_migrate_tfc_to_tfc_multiple_workspace(t *testing.T) {
|
||||
},
|
||||
commands: []tfCommand{
|
||||
{
|
||||
command: []string{"init", "-migrate-state", "-ignore-remote-version"},
|
||||
command: []string{"init", "-ignore-remote-version"},
|
||||
expectedCmdOutput: `Would you like to rename your workspaces?`,
|
||||
userInput: []string{"1", "new-*", "1"},
|
||||
postInputOutput: []string{
|
||||
|
||||
Reference in New Issue
Block a user