2021-10-21 13:19:33 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_backend_apply_before_init(t *testing.T) {
|
2021-11-19 22:03:38 +01:00
|
|
|
t.Parallel()
|
2021-11-12 18:00:24 +01:00
|
|
|
skipIfMissingEnvVar(t)
|
2021-10-28 01:07:12 +02:00
|
|
|
skipWithoutRemoteTerraformVersion(t)
|
|
|
|
|
2021-12-16 21:23:42 +01:00
|
|
|
cases := testCases{
|
2021-10-21 13:19:33 +02:00
|
|
|
"terraform apply with cloud block - blank state": {
|
|
|
|
operations: []operationSets{
|
|
|
|
{
|
|
|
|
prep: func(t *testing.T, orgName, dir string) {
|
|
|
|
wsName := "new-workspace"
|
|
|
|
tfBlock := terraformConfigCloudBackendName(orgName, wsName)
|
|
|
|
writeMainTF(t, tfBlock, dir)
|
|
|
|
},
|
|
|
|
commands: []tfCommand{
|
|
|
|
{
|
|
|
|
command: []string{"apply"},
|
2021-11-13 02:07:10 +01:00
|
|
|
expectedCmdOutput: `Terraform Cloud initialization required: please run "terraform init"`,
|
2021-10-21 13:19:33 +02:00
|
|
|
expectError: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"terraform apply with cloud block - local state": {
|
|
|
|
operations: []operationSets{
|
|
|
|
{
|
|
|
|
prep: func(t *testing.T, orgName, dir string) {
|
|
|
|
tfBlock := terraformConfigLocalBackend()
|
|
|
|
writeMainTF(t, tfBlock, dir)
|
|
|
|
},
|
|
|
|
commands: []tfCommand{
|
|
|
|
{
|
|
|
|
command: []string{"init"},
|
|
|
|
expectedCmdOutput: `Successfully configured the backend "local"!`,
|
|
|
|
},
|
|
|
|
{
|
2021-11-03 21:47:14 +01:00
|
|
|
command: []string{"apply", "-auto-approve"},
|
|
|
|
postInputOutput: []string{`Apply complete!`},
|
2021-10-21 13:19:33 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
prep: func(t *testing.T, orgName, dir string) {
|
|
|
|
wsName := "new-workspace"
|
|
|
|
tfBlock := terraformConfigCloudBackendName(orgName, wsName)
|
|
|
|
writeMainTF(t, tfBlock, dir)
|
|
|
|
},
|
|
|
|
commands: []tfCommand{
|
|
|
|
{
|
|
|
|
command: []string{"apply"},
|
2021-11-13 02:07:10 +01:00
|
|
|
expectedCmdOutput: `Terraform Cloud initialization required: please run "terraform init"`,
|
2021-10-21 13:19:33 +02:00
|
|
|
expectError: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-12-16 21:23:42 +01:00
|
|
|
testRunner(t, cases, 1)
|
2021-10-21 13:19:33 +02:00
|
|
|
}
|