mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-02-20 19:00:38 -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
38 lines
831 B
Go
38 lines
831 B
Go
package differ
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
"github.com/hashicorp/terraform/internal/command/jsonformat/change"
|
|
)
|
|
|
|
func strptr(str string) *string {
|
|
return &str
|
|
}
|
|
|
|
func (v Value) computeAttributeChangeAsPrimitive(ctyType cty.Type) change.Change {
|
|
return v.AsChange(change.Primitive(formatAsPrimitive(v.Before, ctyType), formatAsPrimitive(v.After, ctyType)))
|
|
}
|
|
|
|
func formatAsPrimitive(value interface{}, ctyType cty.Type) *string {
|
|
if value == nil {
|
|
return nil
|
|
}
|
|
|
|
switch {
|
|
case ctyType == cty.String:
|
|
return strptr(fmt.Sprintf("\"%s\"", value))
|
|
case ctyType == cty.Bool:
|
|
if value.(bool) {
|
|
return strptr("true")
|
|
}
|
|
return strptr("false")
|
|
case ctyType == cty.Number:
|
|
return strptr(fmt.Sprintf("%g", value))
|
|
default:
|
|
panic("unrecognized primitive type: " + ctyType.FriendlyName())
|
|
}
|
|
}
|