add AbsOutputAddrs to state outputs
We need all module instance outputs to build the objects for evaluation, but there is no need to copy all the resource instances along with that. This allows us to only return the output states, with enough information to connect them with their module instances.
This commit is contained in:
parent
27cc2aeb9c
commit
e9eb8e04cc
|
@ -259,6 +259,12 @@ func (ms *Module) maybeRestoreResourceInstanceDeposed(addr addrs.ResourceInstanc
|
||||||
// existing value of the same name.
|
// existing value of the same name.
|
||||||
func (ms *Module) SetOutputValue(name string, value cty.Value, sensitive bool) *OutputValue {
|
func (ms *Module) SetOutputValue(name string, value cty.Value, sensitive bool) *OutputValue {
|
||||||
os := &OutputValue{
|
os := &OutputValue{
|
||||||
|
Addr: addrs.AbsOutputValue{
|
||||||
|
Module: ms.Addr,
|
||||||
|
OutputValue: addrs.OutputValue{
|
||||||
|
Name: name,
|
||||||
|
},
|
||||||
|
},
|
||||||
Value: value,
|
Value: value,
|
||||||
Sensitive: sensitive,
|
Sensitive: sensitive,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package states
|
package states
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/hashicorp/terraform/addrs"
|
||||||
"github.com/zclconf/go-cty/cty"
|
"github.com/zclconf/go-cty/cty"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,6 +10,7 @@ import (
|
||||||
// It is not valid to mutate an OutputValue object once it has been created.
|
// It is not valid to mutate an OutputValue object once it has been created.
|
||||||
// Instead, create an entirely new OutputValue to replace the previous one.
|
// Instead, create an entirely new OutputValue to replace the previous one.
|
||||||
type OutputValue struct {
|
type OutputValue struct {
|
||||||
|
Addr addrs.AbsOutputValue
|
||||||
Value cty.Value
|
Value cty.Value
|
||||||
Sensitive bool
|
Sensitive bool
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,6 +226,7 @@ func (os *OutputValue) DeepCopy() *OutputValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &OutputValue{
|
return &OutputValue{
|
||||||
|
Addr: os.Addr,
|
||||||
Value: os.Value,
|
Value: os.Value,
|
||||||
Sensitive: os.Sensitive,
|
Sensitive: os.Sensitive,
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,10 +53,20 @@ func TestState(t *testing.T) {
|
||||||
},
|
},
|
||||||
OutputValues: map[string]*OutputValue{
|
OutputValues: map[string]*OutputValue{
|
||||||
"bar": {
|
"bar": {
|
||||||
|
Addr: addrs.AbsOutputValue{
|
||||||
|
OutputValue: addrs.OutputValue{
|
||||||
|
Name: "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
Value: cty.StringVal("bar value"),
|
Value: cty.StringVal("bar value"),
|
||||||
Sensitive: false,
|
Sensitive: false,
|
||||||
},
|
},
|
||||||
"secret": {
|
"secret": {
|
||||||
|
Addr: addrs.AbsOutputValue{
|
||||||
|
OutputValue: addrs.OutputValue{
|
||||||
|
Name: "secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
Value: cty.StringVal("secret value"),
|
Value: cty.StringVal("secret value"),
|
||||||
Sensitive: true,
|
Sensitive: true,
|
||||||
},
|
},
|
||||||
|
@ -92,6 +102,12 @@ func TestState(t *testing.T) {
|
||||||
LocalValues: map[string]cty.Value{},
|
LocalValues: map[string]cty.Value{},
|
||||||
OutputValues: map[string]*OutputValue{
|
OutputValues: map[string]*OutputValue{
|
||||||
"pizza": {
|
"pizza": {
|
||||||
|
Addr: addrs.AbsOutputValue{
|
||||||
|
Module: addrs.RootModuleInstance.Child("child", addrs.NoKey),
|
||||||
|
OutputValue: addrs.OutputValue{
|
||||||
|
Name: "pizza",
|
||||||
|
},
|
||||||
|
},
|
||||||
Value: cty.StringVal("hawaiian"),
|
Value: cty.StringVal("hawaiian"),
|
||||||
Sensitive: false,
|
Sensitive: false,
|
||||||
},
|
},
|
||||||
|
|
|
@ -281,7 +281,13 @@ func prepareStateV4(sV4 *stateV4) (*File, tfdiags.Diagnostics) {
|
||||||
{
|
{
|
||||||
rootModule := state.RootModule()
|
rootModule := state.RootModule()
|
||||||
for name, fos := range sV4.RootOutputs {
|
for name, fos := range sV4.RootOutputs {
|
||||||
os := &states.OutputValue{}
|
os := &states.OutputValue{
|
||||||
|
Addr: addrs.AbsOutputValue{
|
||||||
|
OutputValue: addrs.OutputValue{
|
||||||
|
Name: name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
os.Sensitive = fos.Sensitive
|
os.Sensitive = fos.Sensitive
|
||||||
|
|
||||||
ty, err := ctyjson.UnmarshalType([]byte(fos.ValueTypeRaw))
|
ty, err := ctyjson.UnmarshalType([]byte(fos.ValueTypeRaw))
|
||||||
|
|
Loading…
Reference in New Issue