github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/command/jsonformat/differ/tuple.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package differ 5 6 import ( 7 "github.com/zclconf/go-cty/cty" 8 9 "github.com/terramate-io/tf/command/jsonformat/collections" 10 "github.com/terramate-io/tf/command/jsonformat/computed" 11 "github.com/terramate-io/tf/command/jsonformat/computed/renderers" 12 "github.com/terramate-io/tf/command/jsonformat/structured" 13 ) 14 15 func computeAttributeDiffAsTuple(change structured.Change, elementTypes []cty.Type) computed.Diff { 16 var elements []computed.Diff 17 current := change.GetDefaultActionForIteration() 18 sliceValue := change.AsSlice() 19 for ix, elementType := range elementTypes { 20 childValue := sliceValue.GetChild(ix, ix) 21 if !childValue.RelevantAttributes.MatchesPartial() { 22 // Mark non-relevant attributes as unchanged. 23 childValue = childValue.AsNoOp() 24 } 25 element := ComputeDiffForType(childValue, elementType) 26 elements = append(elements, element) 27 current = collections.CompareActions(current, element.Action) 28 } 29 return computed.NewDiff(renderers.List(elements), current, change.ReplacePaths.Matches()) 30 }