mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-02-17 19:00:37 -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 * 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
45 lines
1.3 KiB
Go
45 lines
1.3 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 {
|
|
if attribute.AttributeNestedType != nil {
|
|
return v.computeChangeForNestedAttribute(attribute.AttributeNestedType)
|
|
}
|
|
return v.computeChangeForType(unmarshalAttribute(attribute))
|
|
}
|
|
|
|
func (v Value) computeChangeForNestedAttribute(attribute *jsonprovider.NestedType) change.Change {
|
|
switch attribute.NestingMode {
|
|
case "single", "group":
|
|
return v.computeAttributeChangeAsNestedObject(attribute.Attributes)
|
|
default:
|
|
panic("unrecognized nesting mode: " + attribute.NestingMode)
|
|
}
|
|
}
|
|
|
|
func (v Value) computeChangeForType(ctyType cty.Type) change.Change {
|
|
switch {
|
|
case ctyType.IsPrimitiveType():
|
|
return v.computeAttributeChangeAsPrimitive(ctyType)
|
|
case ctyType.IsObjectType():
|
|
return v.computeAttributeChangeAsObject(ctyType.AttributeTypes())
|
|
default:
|
|
panic("not implemented")
|
|
}
|
|
}
|
|
|
|
func unmarshalAttribute(attribute *jsonprovider.Attribute) cty.Type {
|
|
ctyType, err := ctyjson.UnmarshalType(attribute.AttributeType)
|
|
if err != nil {
|
|
panic("could not unmarshal attribute type: " + err.Error())
|
|
}
|
|
return ctyType
|
|
}
|