Skip to content

Commit

Permalink
jsonplan: deterministic relevant attribute order (#36076)
Browse files Browse the repository at this point in the history
* jsonplan: deterministic relevant attribute order

* simplify sort function
  • Loading branch information
liamcervante authored Nov 25, 2024
1 parent b4a634c commit 36d7e87
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/command/jsonplan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,15 @@ func (p *plan) marshalRelevantAttrs(plan *plans.Plan) error {

p.RelevantAttributes = append(p.RelevantAttributes, ResourceAttr{addr, path})
}

// we want our outputs to be deterministic, so we'll sort the attributes
// here. The order of the attributes is not important, as long as it is
// stable.

sort.SliceStable(plan.RelevantAttributes, func(i, j int) bool {
return strings.Compare(fmt.Sprintf("%#v", plan.RelevantAttributes[i]), fmt.Sprintf("%#v", plan.RelevantAttributes[j])) < 0
})

return nil
}

Expand Down

0 comments on commit 36d7e87

Please sign in to comment.