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["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() {
|
||||
newState["workspace"] = workspaceVal
|
||||
workspaceName := backend.DefaultStateName
|
||||
if !workspaceVal.IsNull() {
|
||||
workspaceName = workspaceVal.AsString()
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,8 @@ func TestState_basic(t *testing.T) {
|
|||
"outputs": cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.StringVal("bar"),
|
||||
}),
|
||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||
"workspace": cty.NullVal(cty.String),
|
||||
}),
|
||||
false,
|
||||
},
|
||||
|
@ -80,7 +81,8 @@ func TestState_basic(t *testing.T) {
|
|||
"outputs": cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.StringVal("bar"),
|
||||
}),
|
||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||
"workspace": cty.NullVal(cty.String),
|
||||
}),
|
||||
false,
|
||||
},
|
||||
|
@ -113,7 +115,8 @@ func TestState_basic(t *testing.T) {
|
|||
cty.StringVal("test2"),
|
||||
}),
|
||||
}),
|
||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||
"workspace": cty.NullVal(cty.String),
|
||||
}),
|
||||
false,
|
||||
},
|
||||
|
@ -133,7 +136,8 @@ func TestState_basic(t *testing.T) {
|
|||
"map": 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,
|
||||
},
|
||||
|
@ -158,6 +162,7 @@ func TestState_basic(t *testing.T) {
|
|||
"outputs": cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.StringVal("bar"),
|
||||
}),
|
||||
"workspace": cty.NullVal(cty.String),
|
||||
}),
|
||||
false,
|
||||
},
|
||||
|
@ -173,8 +178,9 @@ func TestState_basic(t *testing.T) {
|
|||
"config": cty.ObjectVal(map[string]cty.Value{
|
||||
"path": cty.StringVal("./testdata/missing.tfstate"),
|
||||
}),
|
||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||
"outputs": cty.EmptyObjectVal,
|
||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||
"outputs": cty.EmptyObjectVal,
|
||||
"workspace": cty.NullVal(cty.String),
|
||||
}),
|
||||
true,
|
||||
},
|
||||
|
@ -225,8 +231,9 @@ func TestState_basic(t *testing.T) {
|
|||
"config": cty.MapVal(map[string]cty.Value{
|
||||
"path": cty.StringVal("./testdata/empty.tfstate"),
|
||||
}),
|
||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||
"outputs": cty.EmptyObjectVal,
|
||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||
"outputs": cty.EmptyObjectVal,
|
||||
"workspace": cty.NullVal(cty.String),
|
||||
}),
|
||||
false,
|
||||
},
|
||||
|
@ -247,6 +254,7 @@ func TestState_basic(t *testing.T) {
|
|||
"outputs": cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.StringVal("bar"),
|
||||
}),
|
||||
"workspace": cty.NullVal(cty.String),
|
||||
}),
|
||||
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" {
|
||||
backend = "local"
|
||||
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