github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/jsonformat/collections/map.go (about) 1 package collections 2 3 import ( 4 "github.com/hashicorp/terraform/internal/command/jsonformat/computed" 5 "github.com/hashicorp/terraform/internal/plans" 6 ) 7 8 type ProcessKey func(key string) computed.Diff 9 10 func TransformMap[Input any](before, after map[string]Input, process ProcessKey) (map[string]computed.Diff, plans.Action) { 11 current := plans.NoOp 12 if before != nil && after == nil { 13 current = plans.Delete 14 } 15 if before == nil && after != nil { 16 current = plans.Create 17 } 18 19 elements := make(map[string]computed.Diff) 20 for key := range before { 21 elements[key] = process(key) 22 current = CompareActions(current, elements[key].Action) 23 } 24 25 for key := range after { 26 if _, ok := elements[key]; ok { 27 // Then we've already processed this key in the before. 28 continue 29 } 30 elements[key] = process(key) 31 current = CompareActions(current, elements[key].Action) 32 } 33 34 return elements, current 35 }