Merge pull request #19732 from hashicorp/jbardin/terraform-remote-state

there is always an implied workspace of "default"
This commit is contained in:
James Bardin 2018-12-21 09:11:18 -05:00 committed by GitHub
commit 725ccea6d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 12 deletions

View File

@ -104,18 +104,15 @@ func dataSourceRemoteStateRead(d *cty.Value) (cty.Value, tfdiags.Diagnostics) {
return cty.NilVal, diags
}
var name string
name := backend.DefaultStateName
if workspaceVal := d.GetAttr("workspace"); !workspaceVal.IsNull() {
newState["workspace"] = workspaceVal
ws := workspaceVal.AsString()
if ws != backend.DefaultStateName {
name = ws
}
} else {
newState["workspace"] = cty.NullVal(cty.String)
name = workspaceVal.AsString()
}
newState["workspace"] = cty.StringVal(name)
state, err := b.StateMgr(name)
if err != nil {
diags = diags.Append(tfdiags.AttributeValue(

View File

@ -4,6 +4,7 @@ import (
"testing"
"github.com/apparentlymart/go-dump/dump"
"github.com/hashicorp/terraform/backend"
"github.com/zclconf/go-cty/cty"
)
@ -34,7 +35,7 @@ func TestState_basic(t *testing.T) {
"outputs": cty.ObjectVal(map[string]cty.Value{
"foo": cty.StringVal("bar"),
}),
"workspace": cty.NullVal(cty.String),
"workspace": cty.StringVal(backend.DefaultStateName),
"defaults": cty.NullVal(cty.DynamicPseudoType),
}),
false,
@ -68,7 +69,7 @@ func TestState_basic(t *testing.T) {
cty.StringVal("test2"),
}),
}),
"workspace": cty.NullVal(cty.String),
"workspace": cty.StringVal(backend.DefaultStateName),
"defaults": cty.NullVal(cty.DynamicPseudoType),
}),
false,
@ -89,7 +90,7 @@ func TestState_basic(t *testing.T) {
"map": cty.NullVal(cty.DynamicPseudoType),
"list": cty.NullVal(cty.DynamicPseudoType),
}),
"workspace": cty.NullVal(cty.String),
"workspace": cty.StringVal(backend.DefaultStateName),
"defaults": cty.NullVal(cty.DynamicPseudoType),
}),
false,
@ -115,7 +116,7 @@ func TestState_basic(t *testing.T) {
"outputs": cty.ObjectVal(map[string]cty.Value{
"foo": cty.StringVal("bar"),
}),
"workspace": cty.NullVal(cty.String),
"workspace": cty.StringVal(backend.DefaultStateName),
}),
false,
},
@ -133,7 +134,7 @@ func TestState_basic(t *testing.T) {
}),
"defaults": cty.NullVal(cty.DynamicPseudoType),
"outputs": cty.EmptyObjectVal,
"workspace": cty.NullVal(cty.String),
"workspace": cty.StringVal(backend.DefaultStateName),
}),
true,
},