check for missing Current instance in EachMap

NoEach and Each list both have this check, but it was missing in
EachMap. Refactor the EachList check to remove a level of indentation,
and make the check consistently near the start of the block.
This commit is contained in:
James Bardin 2019-12-03 11:16:42 -05:00
parent 6728e521c1
commit bff675e0c3
1 changed files with 53 additions and 52 deletions

View File

@ -648,12 +648,18 @@ func (d *evaluationStateData) getResourceInstancesAll(addr addrs.Resource, rng t
for i := 0; i < length; i++ { for i := 0; i < length; i++ {
ty := schema.ImpliedType() ty := schema.ImpliedType()
key := addrs.IntKey(i) key := addrs.IntKey(i)
is, exists := rs.Instances[key] is := rs.Instances[key]
if exists && is.Current != nil { if is == nil || is.Current == nil {
// There shouldn't normally be "gaps" in our list but we'll
// allow it under the assumption that we're in a weird situation
// where e.g. someone has run "terraform state mv" to reorder
// a list and left a hole behind.
vals[i] = cty.UnknownVal(schema.ImpliedType())
continue
}
instAddr := addr.Instance(key).Absolute(d.ModulePath) instAddr := addr.Instance(key).Absolute(d.ModulePath)
// Prefer pending value in plan if present. See getResourceInstanceSingle
// comment for the rationale.
if is.Current.Status == states.ObjectPlanned { if is.Current.Status == states.ObjectPlanned {
if change := d.Evaluator.Changes.GetResourceInstanceChange(instAddr, states.CurrentGen); change != nil { if change := d.Evaluator.Changes.GetResourceInstanceChange(instAddr, states.CurrentGen); change != nil {
val, err := change.After.Decode(ty) val, err := change.After.Decode(ty)
@ -695,13 +701,6 @@ func (d *evaluationStateData) getResourceInstancesAll(addr addrs.Resource, rng t
continue continue
} }
vals[i] = ios.Value vals[i] = ios.Value
} else {
// There shouldn't normally be "gaps" in our list but we'll
// allow it under the assumption that we're in a weird situation
// where e.g. someone has run "terraform state mv" to reorder
// a list and left a hole behind.
vals[i] = cty.UnknownVal(schema.ImpliedType())
}
} }
// We use a tuple rather than a list here because resource schemas may // We use a tuple rather than a list here because resource schemas may
@ -715,12 +714,14 @@ func (d *evaluationStateData) getResourceInstancesAll(addr addrs.Resource, rng t
vals := make(map[string]cty.Value, len(rs.Instances)) vals := make(map[string]cty.Value, len(rs.Instances))
for k, is := range rs.Instances { for k, is := range rs.Instances {
if sk, ok := k.(addrs.StringKey); ok { if sk, ok := k.(addrs.StringKey); ok {
if is == nil || is.Current == nil {
// Assume we're dealing with an instance that hasn't been created yet.
vals[string(sk)] = cty.UnknownVal(schema.ImpliedType())
continue
}
instAddr := addr.Instance(k).Absolute(d.ModulePath) instAddr := addr.Instance(k).Absolute(d.ModulePath)
// Prefer pending value in plan if present. See getResourceInstanceSingle
// comment for the rationale.
// Prefer pending value in plan if present. See getResourceInstanceSingle
// comment for the rationale.
if is.Current.Status == states.ObjectPlanned { if is.Current.Status == states.ObjectPlanned {
if change := d.Evaluator.Changes.GetResourceInstanceChange(instAddr, states.CurrentGen); change != nil { if change := d.Evaluator.Changes.GetResourceInstanceChange(instAddr, states.CurrentGen); change != nil {
val, err := change.After.Decode(ty) val, err := change.After.Decode(ty)