@@ -55,7 +55,6 @@ func testPossibleAttributes(resources []Resource, schema ProviderSchema, tool st
5555 if possibleAttrs , ok := schema .ResourceTypes [resource .Type ]; ok {
5656 usedAttrs := resource .Attributes
5757 unusedAttrsForResource := testFindUnusedAttributes (usedAttrs , possibleAttrs )
58-
5958 // Collect unused attributes
6059 unusedAttrs = append (unusedAttrs , unusedAttrsForResource ... )
6160 } else {
@@ -67,11 +66,34 @@ func testPossibleAttributes(resources []Resource, schema ProviderSchema, tool st
6766
6867// testFindUnusedAttributes identifies unused attributes by comparing used and possible attributes.
6968func testFindUnusedAttributes (usedAttrs map [string ]string , possibleAttrs map [string ]interface {}) []string {
70- var unusedAttrs []string
71- for attr := range possibleAttrs {
72- if _ , used := usedAttrs [attr ]; ! used {
73- unusedAttrs = append (unusedAttrs , attr )
74- }
75- }
76- return unusedAttrs
69+ // Mirror logic in analyzer's findUnusedAttributes: only consider names
70+ // under block.attributes and block.block_types.
71+ validNames := make (map [string ]struct {})
72+
73+ if blockAny , ok := possibleAttrs ["block" ]; ok {
74+ if block , ok := blockAny .(map [string ]interface {}); ok {
75+ if attrsAny , ok := block ["attributes" ]; ok {
76+ if attrsMap , ok := attrsAny .(map [string ]interface {}); ok {
77+ for name := range attrsMap {
78+ validNames [name ] = struct {}{}
79+ }
80+ }
81+ }
82+ if blockTypesAny , ok := block ["block_types" ]; ok {
83+ if btMap , ok := blockTypesAny .(map [string ]interface {}); ok {
84+ for name := range btMap {
85+ validNames [name ] = struct {}{}
86+ }
87+ }
88+ }
89+ }
90+ }
91+
92+ var unused []string
93+ for name := range validNames {
94+ if _ , used := usedAttrs [name ]; ! used {
95+ unused = append (unused , name )
96+ }
97+ }
98+ return unused
7799}
0 commit comments