terraform/provider: compare single statements, empty Sid and scalar conditions canonically

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-12-05 14:18:31 -08:00
1 parent 80aeefaec0
commit 6d8903236e
2 files changed
+30

No files matched your search

@@ -522,3 +522,16 @@ func TestJSONNormalizersPreserveLargeNumbers(t *testing.T) {
t.Fatal("expected trailing JSON to be rejected")
}
}
func TestPoliciesNormalizeStatementShapeSidAndConditions(t *testing.T) {
t.Parallel()
configured := `{"Version":"2012-10-17","Statement":{"Sid":"","Effect":"Allow","Action":"s3:GetObject","Resource":"*","Condition":{"StringEquals":{"aws:username":"alice"}}}}`
seaweedFS := `{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:GetObject"],"Resource":["*"],"Condition":{"StringEquals":{"aws:username":["alice"]}}}]}`
if !policiesSemanticallyEqual(configured, seaweedFS) {
t.Fatal("expected equivalent policy documents to compare equal")
}
if policiesSemanticallyEqual(seaweedFS, `{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:GetObject"],"Resource":["*"],"Condition":{"StringEquals":{"aws:username":["alice","bob"]}}}]}`) {
t.Fatal("expected different condition values to compare different")
}
}
@@ -59,6 +59,7 @@ func normalizePolicyDocument(raw string) (string, error) {
if !ok {
if statement, isObject := document["Statement"].(map[string]any); isObject {
statements = []any{statement}
document["Statement"] = statements
}
}
for _, rawStatement := range statements {
@@ -66,6 +67,22 @@ func normalizePolicyDocument(raw string) (string, error) {
if !ok {
continue
}
if sid, ok := statement["Sid"].(string); ok && sid == "" {
delete(statement, "Sid")
}
if conditions, ok := statement["Condition"].(map[string]any); ok {
for _, rawOperator := range conditions {
operator, ok := rawOperator.(map[string]any)
if !ok {
continue
}
for key, conditionValue := range operator {
if _, isList := conditionValue.([]any); !isList {
operator[key] = []any{conditionValue}
}
}
}
}
for _, key := range []string{"Action", "NotAction", "Resource", "NotResource"} {
if item, ok := statement[key].(string); ok {
if key == "Resource" && item == "" {