update GetModules
Update the GetModule evaluation method with details learned from refactoring the GetResource method.
This commit is contained in:
parent
5fa90d2032
commit
7290e28ca4
|
@ -449,35 +449,41 @@ func (d *evaluationStateData) GetModule(addr addrs.ModuleCall, rng tfdiags.Sourc
|
||||||
// compile the outputs into the correct value type for the each mode
|
// compile the outputs into the correct value type for the each mode
|
||||||
switch {
|
switch {
|
||||||
case callConfig.Count != nil:
|
case callConfig.Count != nil:
|
||||||
vals := make([]cty.Value, len(moduleInstances))
|
// figure out what the last index we have is
|
||||||
for key, instance := range moduleInstances {
|
length := -1
|
||||||
|
for key := range moduleInstances {
|
||||||
intKey, ok := key.(addrs.IntKey)
|
intKey, ok := key.(addrs.IntKey)
|
||||||
if !ok {
|
if !ok {
|
||||||
// old key from state which is being dropped
|
// old key from state which is being dropped
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if int(intKey) >= length {
|
||||||
vals[int(intKey)] = cty.ObjectVal(instance)
|
length = int(intKey) + 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(vals) > 0 {
|
if length > 0 {
|
||||||
// we shouldn't have any holes, but insert real values just in case,
|
vals := make([]cty.Value, length)
|
||||||
// while trimming off any extra values that we may have from guessing
|
for key, instance := range moduleInstances {
|
||||||
// the length via the state instances.
|
intKey, ok := key.(addrs.IntKey)
|
||||||
last := 0
|
if !ok {
|
||||||
|
// old key from state which is being dropped
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
vals[int(intKey)] = cty.ObjectVal(instance)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert unknown values where there are any missing instances
|
||||||
for i, v := range vals {
|
for i, v := range vals {
|
||||||
if v.IsNull() {
|
if v.IsNull() {
|
||||||
vals[i] = cty.DynamicVal
|
vals[i] = cty.DynamicVal
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if i > last {
|
|
||||||
last = i
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
vals = vals[:last+1]
|
|
||||||
ret = cty.TupleVal(vals)
|
ret = cty.TupleVal(vals)
|
||||||
} else {
|
} else {
|
||||||
ret = cty.DynamicVal
|
ret = cty.EmptyTupleVal
|
||||||
}
|
}
|
||||||
|
|
||||||
case callConfig.ForEach != nil:
|
case callConfig.ForEach != nil:
|
||||||
|
@ -494,7 +500,7 @@ func (d *evaluationStateData) GetModule(addr addrs.ModuleCall, rng tfdiags.Sourc
|
||||||
if len(vals) > 0 {
|
if len(vals) > 0 {
|
||||||
ret = cty.ObjectVal(vals)
|
ret = cty.ObjectVal(vals)
|
||||||
} else {
|
} else {
|
||||||
ret = cty.DynamicVal
|
ret = cty.EmptyObjectVal
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue