From 36d7e8706fac72bb0abc60b78f1da23adf6c0ab2 Mon Sep 17 00:00:00 2001 From: Liam Cervante Date: Mon, 25 Nov 2024 14:26:34 +0100 Subject: [PATCH] jsonplan: deterministic relevant attribute order (#36076) * jsonplan: deterministic relevant attribute order * simplify sort function --- internal/command/jsonplan/plan.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/command/jsonplan/plan.go b/internal/command/jsonplan/plan.go index c2f66d6686..e64d373d1d 100644 --- a/internal/command/jsonplan/plan.go +++ b/internal/command/jsonplan/plan.go @@ -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 }