Skip to content

Commit

Permalink
Merge pull request #31246 from hashicorp/jbardin/copy-deps-for-compar…
Browse files Browse the repository at this point in the history
…ison

copy dependency values when sorting
  • Loading branch information
jbardin committed Jun 14, 2022
2 parents e7e3d80 + f1ce3ed commit 9db277a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/terraform/node_resource_plan.go
Expand Up @@ -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
}

Expand Down
8 changes: 8 additions & 0 deletions internal/terraform/node_resource_plan_instance.go
Expand Up @@ -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()
Expand Down

0 comments on commit 9db277a

Please sign in to comment.