mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
Structured plan renderer: Introduce support for multiline and JSON strings (#32488)
* pause implementation * change -> diff, value -> change * add support for json and multiline strings to the primitive renderer * goimports * remove unused function * go fmt * address comments
This commit is contained in:
35
internal/command/jsonformat/collections/map.go
Normal file
35
internal/command/jsonformat/collections/map.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package collections
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform/internal/command/jsonformat/computed"
|
||||
"github.com/hashicorp/terraform/internal/plans"
|
||||
)
|
||||
|
||||
type ProcessKey func(key string) computed.Diff
|
||||
|
||||
func TransformMap[Input any](before, after map[string]Input, process ProcessKey) (map[string]computed.Diff, plans.Action) {
|
||||
current := plans.NoOp
|
||||
if before != nil && after == nil {
|
||||
current = plans.Delete
|
||||
}
|
||||
if before == nil && after != nil {
|
||||
current = plans.Create
|
||||
}
|
||||
|
||||
elements := make(map[string]computed.Diff)
|
||||
for key := range before {
|
||||
elements[key] = process(key)
|
||||
current = CompareActions(current, elements[key].Action)
|
||||
}
|
||||
|
||||
for key := range after {
|
||||
if _, ok := elements[key]; ok {
|
||||
// Then we've already processed this key in the before.
|
||||
continue
|
||||
}
|
||||
elements[key] = process(key)
|
||||
current = CompareActions(current, elements[key].Action)
|
||||
}
|
||||
|
||||
return elements, current
|
||||
}
|
||||
Reference in New Issue
Block a user