mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-21 10:47:34 -05:00
* 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 * goimports
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package differ
|
|
|
|
import (
|
|
"github.com/zclconf/go-cty/cty"
|
|
ctyjson "github.com/zclconf/go-cty/cty/json"
|
|
|
|
"github.com/hashicorp/terraform/internal/command/jsonformat/change"
|
|
"github.com/hashicorp/terraform/internal/command/jsonprovider"
|
|
)
|
|
|
|
func (v Value) ComputeChangeForAttribute(attribute *jsonprovider.Attribute) change.Change {
|
|
return v.ComputeChangeForType(unmarshalAttribute(attribute))
|
|
}
|
|
|
|
func (v Value) ComputeChangeForType(ctyType cty.Type) change.Change {
|
|
switch {
|
|
case ctyType.IsPrimitiveType():
|
|
return v.computeAttributeChangeAsPrimitive(ctyType)
|
|
default:
|
|
panic("not implemented")
|
|
}
|
|
}
|
|
|
|
func unmarshalAttribute(attribute *jsonprovider.Attribute) cty.Type {
|
|
if attribute.AttributeNestedType != nil {
|
|
children := make(map[string]cty.Type)
|
|
for key, child := range attribute.AttributeNestedType.Attributes {
|
|
children[key] = unmarshalAttribute(child)
|
|
}
|
|
return cty.Object(children)
|
|
}
|
|
|
|
ctyType, err := ctyjson.UnmarshalType(attribute.AttributeType)
|
|
if err != nil {
|
|
panic("could not unmarshal attribute type: " + err.Error())
|
|
}
|
|
return ctyType
|
|
}
|