mirror of
https://github.com/hashicorp/terraform.git
synced 2026-03-22 02:20:07 -04:00
29 lines
757 B
Go
29 lines
757 B
Go
// Copyright IBM Corp. 2014, 2026
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
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, keys []string, 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 keys {
|
|
elements[key] = process(key)
|
|
current = CompareActions(current, elements[key].Action)
|
|
}
|
|
|
|
return elements, current
|
|
}
|