2023-01-09 04:05:25 -06:00
|
|
|
package differ
|
|
|
|
|
|
|
|
import (
|
2023-01-09 04:24:01 -06:00
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
ctyjson "github.com/zclconf/go-cty/cty/json"
|
|
|
|
|
2023-01-09 04:05:25 -06:00
|
|
|
"github.com/hashicorp/terraform/internal/command/jsonformat/change"
|
|
|
|
"github.com/hashicorp/terraform/internal/command/jsonprovider"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (v Value) ComputeChangeForAttribute(attribute *jsonprovider.Attribute) change.Change {
|
2023-01-09 04:24:01 -06:00
|
|
|
return v.ComputeChangeForType(unmarshalAttribute(attribute))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v Value) ComputeChangeForType(ctyType cty.Type) change.Change {
|
2023-01-09 04:40:47 -06:00
|
|
|
|
2023-01-09 04:55:55 -06:00
|
|
|
if sensitive, ok := v.checkForSensitive(); ok {
|
2023-01-09 04:40:47 -06:00
|
|
|
return sensitive
|
|
|
|
}
|
|
|
|
|
2023-01-09 04:55:55 -06:00
|
|
|
if computed, ok := v.checkForComputed(ctyType); ok {
|
|
|
|
return computed
|
|
|
|
}
|
|
|
|
|
2023-01-09 04:24:01 -06:00
|
|
|
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
|
2023-01-09 04:05:25 -06:00
|
|
|
}
|