github.com/cycloidio/terraform@v1.1.10-0.20220513142504-76d5c768dc63/cloud/e2e/backend_apply_before_init_test.go (about) 1 package main 2 3 import ( 4 "testing" 5 ) 6 7 func Test_backend_apply_before_init(t *testing.T) { 8 t.Parallel() 9 skipIfMissingEnvVar(t) 10 skipWithoutRemoteTerraformVersion(t) 11 12 cases := testCases{ 13 "terraform apply with cloud block - blank state": { 14 operations: []operationSets{ 15 { 16 prep: func(t *testing.T, orgName, dir string) { 17 wsName := "new-workspace" 18 tfBlock := terraformConfigCloudBackendName(orgName, wsName) 19 writeMainTF(t, tfBlock, dir) 20 }, 21 commands: []tfCommand{ 22 { 23 command: []string{"apply"}, 24 expectedCmdOutput: `Terraform Cloud initialization required: please run "terraform init"`, 25 expectError: true, 26 }, 27 }, 28 }, 29 }, 30 }, 31 "terraform apply with cloud block - local state": { 32 operations: []operationSets{ 33 { 34 prep: func(t *testing.T, orgName, dir string) { 35 tfBlock := terraformConfigLocalBackend() 36 writeMainTF(t, tfBlock, dir) 37 }, 38 commands: []tfCommand{ 39 { 40 command: []string{"init"}, 41 expectedCmdOutput: `Successfully configured the backend "local"!`, 42 }, 43 { 44 command: []string{"apply", "-auto-approve"}, 45 postInputOutput: []string{`Apply complete!`}, 46 }, 47 }, 48 }, 49 { 50 prep: func(t *testing.T, orgName, dir string) { 51 wsName := "new-workspace" 52 tfBlock := terraformConfigCloudBackendName(orgName, wsName) 53 writeMainTF(t, tfBlock, dir) 54 }, 55 commands: []tfCommand{ 56 { 57 command: []string{"apply"}, 58 expectedCmdOutput: `Terraform Cloud initialization required: please run "terraform init"`, 59 expectError: true, 60 }, 61 }, 62 }, 63 }, 64 }, 65 } 66 67 testRunner(t, cases, 1) 68 }