always return original workspace, even when null
The returned value type needs to strictly match the proposed value type.
This commit is contained in:
parent
6ef11e9d9e
commit
a0fad2c6b4
|
@ -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
|
||||||
if workspaceVal := d.GetAttr("workspace"); !workspaceVal.IsNull() {
|
// value, even if we implicitly use a default.
|
||||||
newState["workspace"] = workspaceVal
|
newState["workspace"] = workspaceVal
|
||||||
|
|
||||||
|
workspaceName := backend.DefaultStateName
|
||||||
|
if !workspaceVal.IsNull() {
|
||||||
workspaceName = workspaceVal.AsString()
|
workspaceName = workspaceVal.AsString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ func TestState_basic(t *testing.T) {
|
||||||
"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,
|
||||||
},
|
},
|
||||||
|
@ -81,6 +82,7 @@ func TestState_basic(t *testing.T) {
|
||||||
"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,
|
||||||
},
|
},
|
||||||
|
@ -114,6 +116,7 @@ func TestState_basic(t *testing.T) {
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||||
|
"workspace": cty.NullVal(cty.String),
|
||||||
}),
|
}),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
@ -134,6 +137,7 @@ func TestState_basic(t *testing.T) {
|
||||||
"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,
|
||||||
},
|
},
|
||||||
|
@ -175,6 +180,7 @@ func TestState_basic(t *testing.T) {
|
||||||
}),
|
}),
|
||||||
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
"defaults": cty.NullVal(cty.DynamicPseudoType),
|
||||||
"outputs": cty.EmptyObjectVal,
|
"outputs": cty.EmptyObjectVal,
|
||||||
|
"workspace": cty.NullVal(cty.String),
|
||||||
}),
|
}),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
@ -227,6 +233,7 @@ func TestState_basic(t *testing.T) {
|
||||||
}),
|
}),
|
||||||
"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,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue