mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
Add support for maps in the structured renderer (#32397)
* prep for processing the structured run output * undo unwanted change to a json key * Add skeleton functions and API for refactored renderer * goimports * Fix documentation of the RenderOpts struct * Add rendering functionality for primitives to the structured renderer * add test case for override * Add support for parsing and rendering sensitive values in the renderer * Add support for unknown/computed values in the structured renderer * delete missing unit tests * Add support for object attributes in the structured renderer * goimports * Add support for the replace paths data in the structured renderer * Add support for maps in the structured renderer
This commit is contained in:
45
internal/command/jsonformat/differ/map.go
Normal file
45
internal/command/jsonformat/differ/map.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package differ
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform/internal/command/jsonformat/change"
|
||||
"github.com/hashicorp/terraform/internal/command/jsonprovider"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
func (v Value) computeAttributeChangeAsMap(elementType cty.Type) change.Change {
|
||||
current := v.getDefaultActionForIteration()
|
||||
elements := make(map[string]change.Change)
|
||||
v.processMap(func(key string, value Value) {
|
||||
element := value.ComputeChange(elementType)
|
||||
elements[key] = element
|
||||
current = compareActions(current, element.GetAction())
|
||||
})
|
||||
return change.New(change.Map(elements), current, v.replacePath())
|
||||
}
|
||||
|
||||
func (v Value) computeAttributeChangeAsNestedMap(attributes map[string]*jsonprovider.Attribute) change.Change {
|
||||
current := v.getDefaultActionForIteration()
|
||||
elements := make(map[string]change.Change)
|
||||
v.processMap(func(key string, value Value) {
|
||||
element := value.ComputeChange(attributes)
|
||||
elements[key] = element
|
||||
current = compareActions(current, element.GetAction())
|
||||
})
|
||||
return change.New(change.Map(elements), current, v.replacePath())
|
||||
}
|
||||
|
||||
func (v Value) processMap(process func(key string, value Value)) {
|
||||
mapValue := v.asMap()
|
||||
|
||||
handled := make(map[string]bool)
|
||||
for key := range mapValue.Before {
|
||||
handled[key] = true
|
||||
process(key, mapValue.getChild(key))
|
||||
}
|
||||
for key := range mapValue.After {
|
||||
if _, ok := handled[key]; ok {
|
||||
continue
|
||||
}
|
||||
process(key, mapValue.getChild(key))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user