Skip to content

Commit

Permalink
address review
Browse files Browse the repository at this point in the history
  • Loading branch information
VenelinMartinov committed Nov 25, 2024
1 parent 69348fc commit 897bf79
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
59 changes: 34 additions & 25 deletions pkg/pf/tfbridge/provider_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions pkg/tfbridge/detailed_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 897bf79

Please sign in to comment.