mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-03-01 17:02:38 -05:00
* Rename module name from "github.com/hashicorp/terraform" to "github.com/placeholderplaceholderplaceholder/opentf". Signed-off-by: Jakub Martin <kubam@spacelift.io> * Gofmt. Signed-off-by: Jakub Martin <kubam@spacelift.io> * Regenerate protobuf. Signed-off-by: Jakub Martin <kubam@spacelift.io> * Fix comments. Signed-off-by: Jakub Martin <kubam@spacelift.io> * Undo issue and pull request link changes. Signed-off-by: Jakub Martin <kubam@spacelift.io> * Undo comment changes. Signed-off-by: Jakub Martin <kubam@spacelift.io> * Fix comment. Signed-off-by: Jakub Martin <kubam@spacelift.io> * Undo some link changes. Signed-off-by: Jakub Martin <kubam@spacelift.io> * make generate && make protobuf Signed-off-by: Jakub Martin <kubam@spacelift.io> --------- Signed-off-by: Jakub Martin <kubam@spacelift.io>
85 lines
1.7 KiB
Go
85 lines
1.7 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
tfe "github.com/hashicorp/go-tfe"
|
|
tfversion "github.com/placeholderplaceholderplaceholder/opentf/version"
|
|
)
|
|
|
|
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)
|
|
|
|
cases := testCases{
|
|
"run variables from CLI arg": {
|
|
operations: []operationSets{
|
|
{
|
|
prep: func(t *testing.T, orgName, dir string) {
|
|
wsName := "new-workspace"
|
|
_ = createWorkspace(t, orgName, tfe.WorkspaceCreateOptions{
|
|
Name: tfe.String(wsName),
|
|
TerraformVersion: tfe.String(tfversion.String()),
|
|
})
|
|
tfBlock := terraformConfigRequiredVariable(orgName, wsName)
|
|
writeMainTF(t, tfBlock, dir)
|
|
},
|
|
commands: []tfCommand{
|
|
{
|
|
command: []string{"init"},
|
|
expectedCmdOutput: `Terraform Cloud has been successfully initialized!`,
|
|
},
|
|
{
|
|
command: []string{"plan", "-var", "foo=bar"},
|
|
expectedCmdOutput: ` + test_cli = "bar"`,
|
|
},
|
|
{
|
|
command: []string{"plan", "-var", "foo=bar"},
|
|
expectedCmdOutput: ` + test_env = "qux"`,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
testRunner(t, cases, 1, "TF_CLI_ARGS=-no-color", "TF_VAR_baz=qux")
|
|
}
|