From 5f8d70aafbabcbc61c87294a7e1903d19a5870e3 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 10 Feb 2025 15:28:34 -0500 Subject: [PATCH] sort sensitive paths for consistency --- internal/states/instance_object.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/states/instance_object.go b/internal/states/instance_object.go index f398d01c63..6b4204bbd0 100644 --- a/internal/states/instance_object.go +++ b/internal/states/instance_object.go @@ -11,8 +11,8 @@ import ( ctyjson "github.com/zclconf/go-cty/cty/json" "github.com/hashicorp/terraform/internal/addrs" + "github.com/hashicorp/terraform/internal/lang/format" "github.com/hashicorp/terraform/internal/lang/marks" - "github.com/hashicorp/terraform/internal/tfdiags" ) // ResourceInstanceObject is the local representation of a specific remote @@ -173,8 +173,15 @@ func unmarkValueForStorage(v cty.Value) (unmarkedV cty.Value, sensitivePaths []c if len(withOtherMarks) != 0 { return cty.NilVal, nil, fmt.Errorf( "%s: cannot serialize value marked as %#v for inclusion in a state snapshot (this is a bug in Terraform)", - tfdiags.FormatCtyPath(withOtherMarks[0].Path), withOtherMarks[0].Marks, + format.CtyPath(withOtherMarks[0].Path), withOtherMarks[0].Marks, ) } + + // sort the sensitive paths for consistency in comparison and serialization + sort.Slice(sensitivePaths, func(i, j int) bool { + // use our human-readable format of paths for comparison + return format.CtyPath(sensitivePaths[i]) < format.CtyPath(sensitivePaths[j]) + }) + return val, sensitivePaths, nil }