github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/command/jsonformat/computed/renderers/json.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package renderers 5 6 import ( 7 "github.com/zclconf/go-cty/cty" 8 9 "github.com/terramate-io/tf/command/jsonformat/computed" 10 "github.com/terramate-io/tf/command/jsonformat/jsondiff" 11 "github.com/terramate-io/tf/plans" 12 ) 13 14 // RendererJsonOpts creates a jsondiff.JsonOpts object that returns the correct 15 // embedded renderers for each JSON type. 16 // 17 // We need to define this in our renderers package in order to avoid cycles, and 18 // to help with reuse between the output processing in the differs package, and 19 // our JSON string rendering here. 20 func RendererJsonOpts() jsondiff.JsonOpts { 21 return jsondiff.JsonOpts{ 22 Primitive: func(before, after interface{}, ctype cty.Type, action plans.Action) computed.Diff { 23 return computed.NewDiff(Primitive(before, after, ctype), action, false) 24 }, 25 Object: func(elements map[string]computed.Diff, action plans.Action) computed.Diff { 26 return computed.NewDiff(Object(elements), action, false) 27 }, 28 Array: func(elements []computed.Diff, action plans.Action) computed.Diff { 29 return computed.NewDiff(List(elements), action, false) 30 }, 31 Unknown: func(diff computed.Diff, action plans.Action) computed.Diff { 32 return computed.NewDiff(Unknown(diff), action, false) 33 }, 34 Sensitive: func(diff computed.Diff, beforeSensitive bool, afterSensitive bool, action plans.Action) computed.Diff { 35 return computed.NewDiff(Sensitive(diff, beforeSensitive, afterSensitive), action, false) 36 }, 37 TypeChange: func(before, after computed.Diff, action plans.Action) computed.Diff { 38 return computed.NewDiff(TypeChange(before, after), action, false) 39 }, 40 } 41 }