Merge pull request #25377 from hashicorp/jbardin/remote-state
Correct remote state return value
This commit is contained in:
commit
98ff2065bc
|
@ -97,10 +97,13 @@ func dataSourceRemoteStateRead(d cty.Value) (cty.Value, tfdiags.Diagnostics) {
|
||||||
newState["backend"] = d.GetAttr("backend")
|
newState["backend"] = d.GetAttr("backend")
|
||||||
newState["config"] = d.GetAttr("config")
|
newState["config"] = d.GetAttr("config")
|
||||||
|
|
||||||
workspaceName := backend.DefaultStateName
|
workspaceVal := d.GetAttr("workspace")
|
||||||
|
// This attribute is not computed, so we always have to store the state
|
||||||
|
// value, even if we implicitly use a default.
|
||||||
|
newState["workspace"] = workspaceVal
|
||||||
|
|
||||||
if workspaceVal := d.GetAttr("workspace"); !workspaceVal.IsNull() {
|
workspaceName := backend.DefaultStateName
|
||||||
newState["workspace"] = workspaceVal
|
if !workspaceVal.IsNull() {
|
||||||
workspaceName = workspaceVal.AsString()
|
workspaceName = workspaceVal.AsString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,8 @@ func TestState_basic(t *testing.T) {
|
||||||
"outputs": cty.ObjectVal(map[string]cty.Value{
|
"outputs": cty.ObjectVal(map[string]cty.Value{
|
||||||
"foo": cty.StringVal("bar"),
|
"foo": cty.StringVal("bar"),
|
||||||
}),
|
}),
|
||||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||||
|
"workspace": cty.NullVal(cty.String),
|
||||||
}),
|
}),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
@ -80,7 +81,8 @@ func TestState_basic(t *testing.T) {
|
||||||
"outputs": cty.ObjectVal(map[string]cty.Value{
|
"outputs": cty.ObjectVal(map[string]cty.Value{
|
||||||
"foo": cty.StringVal("bar"),
|
"foo": cty.StringVal("bar"),
|
||||||
}),
|
}),
|
||||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||||
|
"workspace": cty.NullVal(cty.String),
|
||||||
}),
|
}),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
@ -113,7 +115,8 @@ func TestState_basic(t *testing.T) {
|
||||||
cty.StringVal("test2"),
|
cty.StringVal("test2"),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||||
|
"workspace": cty.NullVal(cty.String),
|
||||||
}),
|
}),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
@ -133,7 +136,8 @@ func TestState_basic(t *testing.T) {
|
||||||
"map": cty.NullVal(cty.DynamicPseudoType),
|
"map": cty.NullVal(cty.DynamicPseudoType),
|
||||||
"list": cty.NullVal(cty.DynamicPseudoType),
|
"list": cty.NullVal(cty.DynamicPseudoType),
|
||||||
}),
|
}),
|
||||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||||
|
"workspace": cty.NullVal(cty.String),
|
||||||
}),
|
}),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
@ -158,6 +162,7 @@ func TestState_basic(t *testing.T) {
|
||||||
"outputs": cty.ObjectVal(map[string]cty.Value{
|
"outputs": cty.ObjectVal(map[string]cty.Value{
|
||||||
"foo": cty.StringVal("bar"),
|
"foo": cty.StringVal("bar"),
|
||||||
}),
|
}),
|
||||||
|
"workspace": cty.NullVal(cty.String),
|
||||||
}),
|
}),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
@ -173,8 +178,9 @@ func TestState_basic(t *testing.T) {
|
||||||
"config": cty.ObjectVal(map[string]cty.Value{
|
"config": cty.ObjectVal(map[string]cty.Value{
|
||||||
"path": cty.StringVal("./testdata/missing.tfstate"),
|
"path": cty.StringVal("./testdata/missing.tfstate"),
|
||||||
}),
|
}),
|
||||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||||
"outputs": cty.EmptyObjectVal,
|
"outputs": cty.EmptyObjectVal,
|
||||||
|
"workspace": cty.NullVal(cty.String),
|
||||||
}),
|
}),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
@ -225,8 +231,9 @@ func TestState_basic(t *testing.T) {
|
||||||
"config": cty.MapVal(map[string]cty.Value{
|
"config": cty.MapVal(map[string]cty.Value{
|
||||||
"path": cty.StringVal("./testdata/empty.tfstate"),
|
"path": cty.StringVal("./testdata/empty.tfstate"),
|
||||||
}),
|
}),
|
||||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||||
"outputs": cty.EmptyObjectVal,
|
"outputs": cty.EmptyObjectVal,
|
||||||
|
"workspace": cty.NullVal(cty.String),
|
||||||
}),
|
}),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
@ -247,6 +254,7 @@ func TestState_basic(t *testing.T) {
|
||||||
"outputs": cty.ObjectVal(map[string]cty.Value{
|
"outputs": cty.ObjectVal(map[string]cty.Value{
|
||||||
"foo": cty.StringVal("bar"),
|
"foo": cty.StringVal("bar"),
|
||||||
}),
|
}),
|
||||||
|
"workspace": cty.NullVal(cty.String),
|
||||||
}),
|
}),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package e2etest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/e2e"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTerraformProviderRead(t *testing.T) {
|
||||||
|
// Ensure the terraform provider can correctly read a remote state
|
||||||
|
|
||||||
|
t.Parallel()
|
||||||
|
fixturePath := filepath.Join("testdata", "terraform-provider")
|
||||||
|
tf := e2e.NewBinary(terraformBin, fixturePath)
|
||||||
|
defer tf.Close()
|
||||||
|
|
||||||
|
//// INIT
|
||||||
|
_, stderr, err := tf.Run("init")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected init error: %s\nstderr:\n%s", err, stderr)
|
||||||
|
}
|
||||||
|
|
||||||
|
//// PLAN
|
||||||
|
_, stderr, err = tf.Run("plan")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected plan error: %s\nstderr:\n%s", err, stderr)
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,6 @@ provider "terraform" {
|
||||||
data "terraform_remote_state" "test" {
|
data "terraform_remote_state" "test" {
|
||||||
backend = "local"
|
backend = "local"
|
||||||
config = {
|
config = {
|
||||||
path = "nothing.tfstate"
|
path = "test.tfstate"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"version": 4,
|
||||||
|
"terraform_version": "0.13.0",
|
||||||
|
"serial": 1,
|
||||||
|
"lineage": "8fab7b5a-511c-d586-988e-250f99c8feb4",
|
||||||
|
"outputs": {
|
||||||
|
"out": {
|
||||||
|
"value": "test",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"resources": []
|
||||||
|
}
|
Loading…
Reference in New Issue