mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-13 09:32:24 -06:00
72 lines
1.8 KiB
Go
72 lines
1.8 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package main
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func Test_backend_apply_before_init(t *testing.T) {
|
|
t.Parallel()
|
|
skipIfMissingEnvVar(t)
|
|
skipWithoutRemoteTerraformVersion(t)
|
|
|
|
cases := testCases{
|
|
"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"},
|
|
expectedCmdOutput: `Terraform Cloud initialization required: please run "terraform init"`,
|
|
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"!`,
|
|
},
|
|
{
|
|
command: []string{"apply", "-auto-approve"},
|
|
postInputOutput: []string{`Apply complete!`},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
prep: func(t *testing.T, orgName, dir string) {
|
|
wsName := "new-workspace"
|
|
tfBlock := terraformConfigCloudBackendName(orgName, wsName)
|
|
writeMainTF(t, tfBlock, dir)
|
|
},
|
|
commands: []tfCommand{
|
|
{
|
|
command: []string{"apply"},
|
|
expectedCmdOutput: `Terraform Cloud initialization required: please run "terraform init"`,
|
|
expectError: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
testRunner(t, cases, 1)
|
|
}
|