Skip to content

Commit 81b7e10

Browse files
address review
1 parent 119f9fc commit 81b7e10

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

pkg/pf/tfbridge/provider_diff.go

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -122,31 +122,9 @@ func (p *provider) DiffWithContext(
122122
changes = plugin.DiffSome
123123
}
124124

125-
var pluginDetailedDiff map[string]plugin.PropertyDiff
126-
{
127-
priorProps, err := convert.DecodePropertyMap(ctx, rh.decoder, priorState.state.Value)
128-
if err != nil {
129-
return plugin.DiffResult{}, err
130-
}
131-
132-
props, err := convert.DecodePropertyMap(ctx, rh.decoder, plannedStateValue)
133-
if err != nil {
134-
return plugin.DiffResult{}, err
135-
}
136-
137-
detailedDiff := tfbridge.MakeDetailedDiffV2(
138-
ctx,
139-
rh.schemaOnlyShimResource.Schema(),
140-
rh.pulumiResourceInfo.GetFields(),
141-
priorProps,
142-
props,
143-
checkedInputs,
144-
)
145-
146-
pluginDetailedDiff = make(map[string]plugin.PropertyDiff, len(detailedDiff))
147-
for k, v := range detailedDiff {
148-
pluginDetailedDiff[k] = plugin.PropertyDiff{Kind: plugin.DiffKind(v.Kind), InputDiff: v.InputDiff}
149-
}
125+
pluginDetailedDiff, err := calculateDetailedDiff(ctx, &rh, priorState, plannedStateValue, checkedInputs)
126+
if err != nil {
127+
return plugin.DiffResult{}, err
150128
}
151129

152130
diffResult := plugin.DiffResult{
@@ -161,6 +139,37 @@ func (p *provider) DiffWithContext(
161139
return diffResult, nil
162140
}
163141

142+
func calculateDetailedDiff(
143+
ctx context.Context, rh *resourceHandle, priorState *upgradedResourceState,
144+
plannedStateValue tftypes.Value, checkedInputs resource.PropertyMap,
145+
) (map[string]plugin.PropertyDiff, error) {
146+
priorProps, err := convert.DecodePropertyMap(ctx, rh.decoder, priorState.state.Value)
147+
if err != nil {
148+
return nil, err
149+
}
150+
151+
props, err := convert.DecodePropertyMap(ctx, rh.decoder, plannedStateValue)
152+
if err != nil {
153+
return nil, err
154+
}
155+
156+
detailedDiff := tfbridge.MakeDetailedDiffV2(
157+
ctx,
158+
rh.schemaOnlyShimResource.Schema(),
159+
rh.pulumiResourceInfo.GetFields(),
160+
priorProps,
161+
props,
162+
checkedInputs,
163+
)
164+
165+
pluginDetailedDiff := make(map[string]plugin.PropertyDiff, len(detailedDiff))
166+
for k, v := range detailedDiff {
167+
pluginDetailedDiff[k] = plugin.PropertyDiff{Kind: plugin.DiffKind(v.Kind), InputDiff: v.InputDiff}
168+
}
169+
170+
return pluginDetailedDiff, nil
171+
}
172+
164173
// For each path x.y.z extracts the next step x and converts it to a matching Pulumi key. Removes
165174
// duplicates and orders the result.
166175
func topLevelPropertyKeySet(

pkg/tfbridge/detailed_diff.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ func (differ detailedDiffer) makeDetailedDiffPropertyMap(
474474
return result
475475
}
476476

477+
// MakeDetailedDiffV2 is the main entry point for calculating the detailed diff.
478+
// This is an internal function that should not be used outside of the pulumi-terraform-bridge.
477479
func MakeDetailedDiffV2(
478480
ctx context.Context,
479481
tfs shim.SchemaMap,

0 commit comments

Comments
 (0)