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:
James Bardin 2020-04-13 16:37:59 -04:00
parent 27cc2aeb9c
commit e9eb8e04cc
5 changed files with 32 additions and 1 deletions

View File

@ -259,6 +259,12 @@ func (ms *Module) maybeRestoreResourceInstanceDeposed(addr addrs.ResourceInstanc
// existing value of the same name.
func (ms *Module) SetOutputValue(name string, value cty.Value, sensitive bool) *OutputValue {
os := &OutputValue{
Addr: addrs.AbsOutputValue{
Module: ms.Addr,
OutputValue: addrs.OutputValue{
Name: name,
},
},
Value: value,
Sensitive: sensitive,
}

View File

@ -1,6 +1,7 @@
package states
import (
"github.com/hashicorp/terraform/addrs"
"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.
// Instead, create an entirely new OutputValue to replace the previous one.
type OutputValue struct {
Addr addrs.AbsOutputValue
Value cty.Value
Sensitive bool
}

View File

@ -226,6 +226,7 @@ func (os *OutputValue) DeepCopy() *OutputValue {
}
return &OutputValue{
Addr: os.Addr,
Value: os.Value,
Sensitive: os.Sensitive,
}

View File

@ -53,10 +53,20 @@ func TestState(t *testing.T) {
},
OutputValues: map[string]*OutputValue{
"bar": {
Addr: addrs.AbsOutputValue{
OutputValue: addrs.OutputValue{
Name: "bar",
},
},
Value: cty.StringVal("bar value"),
Sensitive: false,
},
"secret": {
Addr: addrs.AbsOutputValue{
OutputValue: addrs.OutputValue{
Name: "secret",
},
},
Value: cty.StringVal("secret value"),
Sensitive: true,
},
@ -92,6 +102,12 @@ func TestState(t *testing.T) {
LocalValues: map[string]cty.Value{},
OutputValues: map[string]*OutputValue{
"pizza": {
Addr: addrs.AbsOutputValue{
Module: addrs.RootModuleInstance.Child("child", addrs.NoKey),
OutputValue: addrs.OutputValue{
Name: "pizza",
},
},
Value: cty.StringVal("hawaiian"),
Sensitive: false,
},

View File

@ -281,7 +281,13 @@ func prepareStateV4(sV4 *stateV4) (*File, tfdiags.Diagnostics) {
{
rootModule := state.RootModule()
for name, fos := range sV4.RootOutputs {
os := &states.OutputValue{}
os := &states.OutputValue{
Addr: addrs.AbsOutputValue{
OutputValue: addrs.OutputValue{
Name: name,
},
},
}
os.Sensitive = fos.Sensitive
ty, err := ctyjson.UnmarshalType([]byte(fos.ValueTypeRaw))