update evaluation to use state ModuleOutputs

This way we don't need the extra copy of the entire module.
This commit is contained in:
James Bardin 2020-04-13 18:17:08 -04:00
parent 2c4c027a97
commit ad069b7416
1 changed files with 6 additions and 12 deletions

View File

@ -370,23 +370,15 @@ func (d *evaluationStateData) GetModule(addr addrs.ModuleCall, rng tfdiags.Sourc
// We know the instance path up to this point, and the child module name, // We know the instance path up to this point, and the child module name,
// so we only need to store these by instance key. // so we only need to store these by instance key.
stateMap := map[addrs.InstanceKey]map[string]cty.Value{} stateMap := map[addrs.InstanceKey]map[string]cty.Value{}
for _, m := range d.Evaluator.State.ModuleInstances(moduleAddr) { for _, output := range d.Evaluator.State.ModuleOutputs(d.ModulePath, addr) {
// skip module instances that aren't a child of our particular parent _, callInstance := output.Addr.Module.CallInstance()
// module instance.
if !d.ModulePath.Equal(m.Addr.Parent()) {
continue
}
_, callInstance := m.Addr.CallInstance()
instance, ok := stateMap[callInstance.Key] instance, ok := stateMap[callInstance.Key]
if !ok { if !ok {
instance = map[string]cty.Value{} instance = map[string]cty.Value{}
stateMap[callInstance.Key] = instance stateMap[callInstance.Key] = instance
} }
for name, output := range m.OutputValues { instance[output.Addr.OutputValue.Name] = output.Value
instance[name] = output.Value
}
} }
// Get all changes that reside for this module call within our path. // Get all changes that reside for this module call within our path.
@ -414,7 +406,9 @@ func (d *evaluationStateData) GetModule(addr addrs.ModuleCall, rng tfdiags.Sourc
for key, states := range stateMap { for key, states := range stateMap {
outputState, ok := states[cfg.Name] outputState, ok := states[cfg.Name]
if !ok { if !ok {
continue // we'll take this chance to insert any missing values that are
// defined in the config
outputState = cty.DynamicVal
} }
instance, ok := moduleInstances[key] instance, ok := moduleInstances[key]