Skip to content

Commit f1ce3ed

Browse files
committed
copy dependency values when sorting
Expanded resource instances can initially share the same dependency slice, so we must take care to not modify the array values when checking the dependencies. In the future we can convert these to a generic Set data type, as we often need to compare for equality and take the union of multiple groups of dependencies.
1 parent 0db7557 commit f1ce3ed

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

internal/terraform/node_resource_plan.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ type nodeExpandPlannableResource struct {
3838

3939
// We attach dependencies to the Resource during refresh, since the
4040
// instances are instantiated during DynamicExpand.
41+
// FIXME: These would be better off converted to a generic Set data
42+
// structure in the future, as we need to compare for equality and take the
43+
// union of multiple groups of dependencies.
4144
dependencies []addrs.ConfigResource
4245
}
4346

internal/terraform/node_resource_plan_instance.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,14 @@ func depsEqual(a, b []addrs.ConfigResource) bool {
391391
return false
392392
}
393393

394+
// Because we need to sort the deps to compare equality, make shallow
395+
// copies to prevent concurrently modifying the array values on
396+
// dependencies shared between expanded instances.
397+
copyA, copyB := make([]addrs.ConfigResource, len(a)), make([]addrs.ConfigResource, len(b))
398+
copy(copyA, a)
399+
copy(copyB, b)
400+
a, b = copyA, copyB
401+
394402
less := func(s []addrs.ConfigResource) func(i, j int) bool {
395403
return func(i, j int) bool {
396404
return s[i].String() < s[j].String()

0 commit comments

Comments
 (0)