github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/jsonformat/differ/map.go (about)

     1  package differ
     2  
     3  import (
     4  	"github.com/zclconf/go-cty/cty"
     5  
     6  	"github.com/hashicorp/terraform/internal/command/jsonformat/collections"
     7  	"github.com/hashicorp/terraform/internal/command/jsonformat/computed"
     8  	"github.com/hashicorp/terraform/internal/command/jsonformat/computed/renderers"
     9  	"github.com/hashicorp/terraform/internal/command/jsonprovider"
    10  	"github.com/hashicorp/terraform/internal/plans"
    11  )
    12  
    13  func (change Change) computeAttributeDiffAsMap(elementType cty.Type) computed.Diff {
    14  	mapValue := change.asMap()
    15  	elements, current := collections.TransformMap(mapValue.Before, mapValue.After, func(key string) computed.Diff {
    16  		value := mapValue.getChild(key)
    17  		if !value.RelevantAttributes.MatchesPartial() {
    18  			// Mark non-relevant attributes as unchanged.
    19  			value = value.AsNoOp()
    20  		}
    21  		return value.ComputeDiffForType(elementType)
    22  	})
    23  	return computed.NewDiff(renderers.Map(elements), current, change.ReplacePaths.Matches())
    24  }
    25  
    26  func (change Change) computeAttributeDiffAsNestedMap(attributes map[string]*jsonprovider.Attribute) computed.Diff {
    27  	mapValue := change.asMap()
    28  	elements, current := collections.TransformMap(mapValue.Before, mapValue.After, func(key string) computed.Diff {
    29  		value := mapValue.getChild(key)
    30  		if !value.RelevantAttributes.MatchesPartial() {
    31  			// Mark non-relevant attributes as unchanged.
    32  			value = value.AsNoOp()
    33  		}
    34  		return value.computeDiffForNestedAttribute(&jsonprovider.NestedType{
    35  			Attributes:  attributes,
    36  			NestingMode: "single",
    37  		})
    38  	})
    39  	return computed.NewDiff(renderers.NestedMap(elements), current, change.ReplacePaths.Matches())
    40  }
    41  
    42  func (change Change) computeBlockDiffsAsMap(block *jsonprovider.Block) (map[string]computed.Diff, plans.Action) {
    43  	mapValue := change.asMap()
    44  	return collections.TransformMap(mapValue.Before, mapValue.After, func(key string) computed.Diff {
    45  		value := mapValue.getChild(key)
    46  		if !value.RelevantAttributes.MatchesPartial() {
    47  			// Mark non-relevant attributes as unchanged.
    48  			value = value.AsNoOp()
    49  		}
    50  		return value.ComputeDiffForBlock(block)
    51  	})
    52  }