mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-23 11:44:26 -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 * Add support for the replace paths data in the structured renderer * Add support for maps in the structured renderer * Add support for lists in the structured renderer * goimports * Add support for sets in the structured renderer * goimports * Add support for blocks in the structured renderer * goimports * Add support for outputs in the structured renderer * fix ordering of blocks * remove unused test stub * fix typo
61 lines
1.9 KiB
Go
61 lines
1.9 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)
|
|
case "map":
|
|
return v.computeAttributeChangeAsNestedMap(attribute.Attributes)
|
|
case "list":
|
|
return v.computeAttributeChangeAsNestedList(attribute.Attributes)
|
|
case "set":
|
|
return v.computeAttributeChangeAsNestedSet(attribute.Attributes)
|
|
default:
|
|
panic("unrecognized nesting mode: " + attribute.NestingMode)
|
|
}
|
|
}
|
|
|
|
func (v Value) computeChangeForType(ctyType cty.Type) change.Change {
|
|
if ctyType == cty.NilType {
|
|
return v.ComputeChangeForOutput()
|
|
}
|
|
|
|
switch {
|
|
case ctyType.IsPrimitiveType():
|
|
return v.computeAttributeChangeAsPrimitive(ctyType)
|
|
case ctyType.IsObjectType():
|
|
return v.computeAttributeChangeAsObject(ctyType.AttributeTypes())
|
|
case ctyType.IsMapType():
|
|
return v.computeAttributeChangeAsMap(ctyType.ElementType())
|
|
case ctyType.IsListType():
|
|
return v.computeAttributeChangeAsList(ctyType.ElementType())
|
|
case ctyType.IsSetType():
|
|
return v.computeAttributeChangeAsSet(ctyType.ElementType())
|
|
default:
|
|
panic("unrecognized type: " + ctyType.FriendlyName())
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|