diff --git a/internal/terraform/node_resource_plan.go b/internal/terraform/node_resource_plan.go index 5a01d9337dcf..1ee94c7435f0 100644 --- a/internal/terraform/node_resource_plan.go +++ b/internal/terraform/node_resource_plan.go @@ -38,6 +38,9 @@ type nodeExpandPlannableResource struct { // We attach dependencies to the Resource during refresh, since the // instances are instantiated during DynamicExpand. + // FIXME: These would be better off converted to a generic Set data + // structure in the future, as we need to compare for equality and take the + // union of multiple groups of dependencies. dependencies []addrs.ConfigResource } diff --git a/internal/terraform/node_resource_plan_instance.go b/internal/terraform/node_resource_plan_instance.go index 46ca37f7de2c..14bded923aa3 100644 --- a/internal/terraform/node_resource_plan_instance.go +++ b/internal/terraform/node_resource_plan_instance.go @@ -391,6 +391,14 @@ func depsEqual(a, b []addrs.ConfigResource) bool { return false } + // Because we need to sort the deps to compare equality, make shallow + // copies to prevent concurrently modifying the array values on + // dependencies shared between expanded instances. + copyA, copyB := make([]addrs.ConfigResource, len(a)), make([]addrs.ConfigResource, len(b)) + copy(copyA, a) + copy(copyB, b) + a, b = copyA, copyB + less := func(s []addrs.ConfigResource) func(i, j int) bool { return func(i, j int) bool { return s[i].String() < s[j].String()