Skip to content

Commit ebc7a28

Browse files
committed
WIP: try to bubble up resource replacements to module replacements
1 parent 8279c90 commit ebc7a28

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

pkg/modprovider/module.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ func (h *moduleHandler) Diff(
9191
return nil, err
9292
}
9393

94+
inputsChanged := false
9495
if !oldInputs.DeepEquals(newInputs) {
95-
// Inputs have changed, so we need tell the engine that an update is needed.
96-
return &pulumirpc.DiffResponse{Changes: pulumirpc.DiffResponse_DIFF_SOME}, nil
96+
inputsChanged = true
9797
}
9898

9999
// Here, inputs have not changes but the underlying module might have changed
@@ -106,7 +106,7 @@ func (h *moduleHandler) Diff(
106106
tf, err := h.prepSandbox(
107107
ctx,
108108
urn,
109-
oldInputs,
109+
newInputs,
110110
oldOutputs,
111111
inferredModule,
112112
moduleSource,
@@ -123,12 +123,19 @@ func (h *moduleHandler) Diff(
123123
return nil, fmt.Errorf("error performing plan during Diff(...) %w", err)
124124
}
125125

126+
replaceKeys := []string{}
126127
resourcesChanged := false
127-
plan.VisitResourcePlans(func(resource *tfsandbox.ResourcePlan) {
128-
if resource.ChangeKind() != tfsandbox.NoOp {
128+
plan.VisitResourcePlans(func(res *tfsandbox.ResourcePlan) {
129+
println("Visiting resource plan for", res.Address())
130+
println("Change kind is", res.ChangeKind())
131+
if res.ChangeKind() != tfsandbox.NoOp {
129132
// if there is any resource change that is not a no-op, we need to update.
130133
resourcesChanged = true
131134
}
135+
// Add any resources that are replacing to the replaceKeys list.
136+
if res.ChangeKind() == tfsandbox.Replace || res.ChangeKind() == tfsandbox.ReplaceDestroyBeforeCreate {
137+
replaceKeys = append(replaceKeys, string(res.Address()))
138+
}
132139
})
133140

134141
outputsChanged := false
@@ -139,8 +146,16 @@ func (h *moduleHandler) Diff(
139146
}
140147
}
141148

142-
if resourcesChanged || outputsChanged {
143-
return &pulumirpc.DiffResponse{Changes: pulumirpc.DiffResponse_DIFF_SOME}, nil
149+
println("Is it DIFF_SOME?", inputsChanged || resourcesChanged || outputsChanged)
150+
println("inputsChanged?", inputsChanged)
151+
println("resourcesChanged?", resourcesChanged)
152+
println("outputsChanged?", outputsChanged)
153+
154+
if inputsChanged || resourcesChanged || outputsChanged {
155+
return &pulumirpc.DiffResponse{
156+
Changes: pulumirpc.DiffResponse_DIFF_SOME,
157+
Replaces: replaceKeys,
158+
}, nil
144159
}
145160

146161
// the module has not changed, return DIFF_NONE.

0 commit comments

Comments
 (0)