Merge pull request #23550 from hashicorp/jbardin/get_resource_panic
check for missing Current instance in EachMap
This commit is contained in:
commit
07edc211eb
|
@ -648,12 +648,18 @@ func (d *evaluationStateData) getResourceInstancesAll(addr addrs.Resource, rng t
|
|||
for i := 0; i < length; i++ {
|
||||
ty := schema.ImpliedType()
|
||||
key := addrs.IntKey(i)
|
||||
is, exists := rs.Instances[key]
|
||||
if exists && is.Current != nil {
|
||||
is := rs.Instances[key]
|
||||
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)
|
||||
|
||||
// Prefer pending value in plan if present. See getResourceInstanceSingle
|
||||
// comment for the rationale.
|
||||
if is.Current.Status == states.ObjectPlanned {
|
||||
if change := d.Evaluator.Changes.GetResourceInstanceChange(instAddr, states.CurrentGen); change != nil {
|
||||
val, err := change.After.Decode(ty)
|
||||
|
@ -695,13 +701,6 @@ func (d *evaluationStateData) getResourceInstancesAll(addr addrs.Resource, rng t
|
|||
continue
|
||||
}
|
||||
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
|
||||
|
@ -715,12 +714,14 @@ func (d *evaluationStateData) getResourceInstancesAll(addr addrs.Resource, rng t
|
|||
vals := make(map[string]cty.Value, len(rs.Instances))
|
||||
for k, is := range rs.Instances {
|
||||
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)
|
||||
|
||||
// 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 change := d.Evaluator.Changes.GetResourceInstanceChange(instAddr, states.CurrentGen); change != nil {
|
||||
val, err := change.After.Decode(ty)
|
||||
|
|
Loading…
Reference in New Issue