github.com/opentofu/opentofu@v1.7.1/internal/command/jsonformat/computed/renderers/json.go (about)

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