terraform/internal/cloud/e2e/run_variables_test.go

82 lines
1.6 KiB
Go
Raw Normal View History

2021-10-12 00:14:44 +02:00
package main
import (
"fmt"
"testing"
2021-11-11 21:21:21 +01:00
tfe "github.com/hashicorp/go-tfe"
tfversion "github.com/hashicorp/terraform/version"
2021-10-12 00:14:44 +02:00
)
func terraformConfigRequiredVariable(org, name string) string {
return fmt.Sprintf(`
terraform {
cloud {
hostname = "%s"
organization = "%s"
workspaces {
name = "%s"
}
}
}
variable "foo" {
type = string
}
variable "baz" {
type = string
}
output "test_cli" {
value = var.foo
}
output "test_env" {
value = var.baz
}
`, tfeHostname, org, name)
}
func Test_cloud_run_variables(t *testing.T) {
t.Parallel()
skipIfMissingEnvVar(t)
skipWithoutRemoteTerraformVersion(t)
2021-10-12 00:14:44 +02:00
cases := testCases{
"run variables from CLI arg": {
operations: []operationSets{
{
prep: func(t *testing.T, orgName, dir string) {
wsName := "new-workspace"
2021-11-11 21:21:21 +01:00
_ = createWorkspace(t, orgName, tfe.WorkspaceCreateOptions{
Name: tfe.String(wsName),
TerraformVersion: tfe.String(tfversion.String()),
})
2021-10-12 00:14:44 +02:00
tfBlock := terraformConfigRequiredVariable(orgName, wsName)
writeMainTF(t, tfBlock, dir)
},
commands: []tfCommand{
{
command: []string{"init"},
2021-10-24 06:33:52 +02:00
expectedCmdOutput: `Terraform Cloud has been successfully initialized!`,
2021-10-12 00:14:44 +02:00
},
{
command: []string{"plan", "-var", "foo=bar"},
expectedCmdOutput: ` + test_cli = "bar"`,
2021-10-12 00:14:44 +02:00
},
{
command: []string{"plan", "-var", "foo=bar"},
expectedCmdOutput: ` + test_env = "qux"`,
2021-10-12 00:14:44 +02:00
},
},
},
},
},
}
testRunner(t, cases, 1, "TF_CLI_ARGS=-no-color", "TF_VAR_baz=qux")
2021-10-12 00:14:44 +02:00
}