2023-01-09 10:39:13 -06:00
|
|
|
package differ
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
2023-01-09 13:22:59 -06:00
|
|
|
|
2023-01-11 02:35:36 -06:00
|
|
|
"github.com/hashicorp/terraform/internal/command/jsonformat/collections"
|
2023-01-10 10:24:48 -06:00
|
|
|
"github.com/hashicorp/terraform/internal/command/jsonformat/computed"
|
|
|
|
"github.com/hashicorp/terraform/internal/command/jsonformat/computed/renderers"
|
2023-04-21 02:51:55 -05:00
|
|
|
"github.com/hashicorp/terraform/internal/command/jsonformat/structured"
|
2023-01-09 10:39:13 -06:00
|
|
|
)
|
|
|
|
|
2023-04-21 02:51:55 -05:00
|
|
|
func computeAttributeDiffAsTuple(change structured.Change, elementTypes []cty.Type) computed.Diff {
|
2023-01-10 10:24:48 -06:00
|
|
|
var elements []computed.Diff
|
2023-04-21 02:51:55 -05:00
|
|
|
current := change.GetDefaultActionForIteration()
|
|
|
|
sliceValue := change.AsSlice()
|
2023-01-09 10:39:13 -06:00
|
|
|
for ix, elementType := range elementTypes {
|
2023-04-21 02:51:55 -05:00
|
|
|
childValue := sliceValue.GetChild(ix, ix)
|
2023-01-16 08:18:38 -06:00
|
|
|
if !childValue.RelevantAttributes.MatchesPartial() {
|
|
|
|
// Mark non-relevant attributes as unchanged.
|
|
|
|
childValue = childValue.AsNoOp()
|
|
|
|
}
|
2023-04-21 02:51:55 -05:00
|
|
|
element := ComputeDiffForType(childValue, elementType)
|
2023-01-09 10:39:13 -06:00
|
|
|
elements = append(elements, element)
|
2023-01-11 02:35:36 -06:00
|
|
|
current = collections.CompareActions(current, element.Action)
|
2023-01-09 10:39:13 -06:00
|
|
|
}
|
2023-01-16 08:18:38 -06:00
|
|
|
return computed.NewDiff(renderers.List(elements), current, change.ReplacePaths.Matches())
|
2023-01-09 10:39:13 -06:00
|
|
|
}
|