From 897bf79d9ad4c54e781f7b19a0c31c2e129e1d8f Mon Sep 17 00:00:00 2001 From: Venelin Date: Mon, 25 Nov 2024 13:08:00 +0000 Subject: [PATCH] address review --- pkg/pf/tfbridge/provider_diff.go | 59 ++++++++++++++++++-------------- pkg/tfbridge/detailed_diff.go | 2 ++ 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/pkg/pf/tfbridge/provider_diff.go b/pkg/pf/tfbridge/provider_diff.go index c02f136ea..cf045c559 100644 --- a/pkg/pf/tfbridge/provider_diff.go +++ b/pkg/pf/tfbridge/provider_diff.go @@ -122,31 +122,9 @@ func (p *provider) DiffWithContext( changes = plugin.DiffSome } - var pluginDetailedDiff map[string]plugin.PropertyDiff - { - priorProps, err := convert.DecodePropertyMap(ctx, rh.decoder, priorState.state.Value) - if err != nil { - return plugin.DiffResult{}, err - } - - props, err := convert.DecodePropertyMap(ctx, rh.decoder, plannedStateValue) - if err != nil { - return plugin.DiffResult{}, err - } - - detailedDiff := tfbridge.MakeDetailedDiffV2( - ctx, - rh.schemaOnlyShimResource.Schema(), - rh.pulumiResourceInfo.GetFields(), - priorProps, - props, - checkedInputs, - ) - - pluginDetailedDiff = make(map[string]plugin.PropertyDiff, len(detailedDiff)) - for k, v := range detailedDiff { - pluginDetailedDiff[k] = plugin.PropertyDiff{Kind: plugin.DiffKind(v.Kind), InputDiff: v.InputDiff} - } + pluginDetailedDiff, err := calculateDetailedDiff(ctx, &rh, priorState, plannedStateValue, checkedInputs) + if err != nil { + return plugin.DiffResult{}, err } diffResult := plugin.DiffResult{ @@ -161,6 +139,37 @@ func (p *provider) DiffWithContext( return diffResult, nil } +func calculateDetailedDiff( + ctx context.Context, rh *resourceHandle, priorState *upgradedResourceState, + plannedStateValue tftypes.Value, checkedInputs resource.PropertyMap, +) (map[string]plugin.PropertyDiff, error) { + priorProps, err := convert.DecodePropertyMap(ctx, rh.decoder, priorState.state.Value) + if err != nil { + return nil, err + } + + props, err := convert.DecodePropertyMap(ctx, rh.decoder, plannedStateValue) + if err != nil { + return nil, err + } + + detailedDiff := tfbridge.MakeDetailedDiffV2( + ctx, + rh.schemaOnlyShimResource.Schema(), + rh.pulumiResourceInfo.GetFields(), + priorProps, + props, + checkedInputs, + ) + + pluginDetailedDiff := make(map[string]plugin.PropertyDiff, len(detailedDiff)) + for k, v := range detailedDiff { + pluginDetailedDiff[k] = plugin.PropertyDiff{Kind: plugin.DiffKind(v.Kind), InputDiff: v.InputDiff} + } + + return pluginDetailedDiff, nil +} + // For each path x.y.z extracts the next step x and converts it to a matching Pulumi key. Removes // duplicates and orders the result. func topLevelPropertyKeySet( diff --git a/pkg/tfbridge/detailed_diff.go b/pkg/tfbridge/detailed_diff.go index 6566cc7d0..a50e8563b 100644 --- a/pkg/tfbridge/detailed_diff.go +++ b/pkg/tfbridge/detailed_diff.go @@ -474,6 +474,8 @@ func (differ detailedDiffer) makeDetailedDiffPropertyMap( return result } +// MakeDetailedDiffV2 is the main entry point for calculating the detailed diff. +// This is an internal function that should not be used outside of the pulumi-terraform-bridge. func MakeDetailedDiffV2( ctx context.Context, tfs shim.SchemaMap,