Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions pkg/modprovider/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ func (h *moduleHandler) Diff(
return nil, err
}

inputsChanged := false
if !oldInputs.DeepEquals(newInputs) {
// Inputs have changed, so we need tell the engine that an update is needed.
return &pulumirpc.DiffResponse{Changes: pulumirpc.DiffResponse_DIFF_SOME}, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks suspect as it's tricky to reason about short-circuit here, thinking.

inputsChanged = true
}

// Here, inputs have not changes but the underlying module might have changed
Expand All @@ -142,7 +142,7 @@ func (h *moduleHandler) Diff(
tf, err := h.prepSandbox(
ctx,
urn,
oldInputs,
newInputs,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks suspect! Why the change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. @Zaid-Ajaj explains that before the change oldInputs.DeepEquals(newInputs) made them the same.

oldOutputs,
inferredModule,
moduleSource,
Expand All @@ -159,12 +159,19 @@ func (h *moduleHandler) Diff(
return nil, fmt.Errorf("error performing plan during Diff(...) %w", err)
}

replaceKeys := []string{}
resourcesChanged := false
plan.VisitResourcePlans(func(resource *tfsandbox.ResourcePlan) {
if resource.ChangeKind() != tfsandbox.NoOp {
plan.VisitResourcePlans(func(res *tfsandbox.ResourcePlan) {
println("Visiting resource plan for", res.Address())
println("Change kind is", res.ChangeKind())
if res.ChangeKind() != tfsandbox.NoOp {
// if there is any resource change that is not a no-op, we need to update.
resourcesChanged = true
}
// Add any resources that are replacing to the replaceKeys list.
if res.ChangeKind() == tfsandbox.Replace || res.ChangeKind() == tfsandbox.ReplaceDestroyBeforeCreate {
replaceKeys = append(replaceKeys, string(res.Address()))
}
})

outputsChanged := false
Expand All @@ -175,8 +182,20 @@ func (h *moduleHandler) Diff(
}
}

if resourcesChanged || outputsChanged {
return &pulumirpc.DiffResponse{Changes: pulumirpc.DiffResponse_DIFF_SOME}, nil
println("Is it DIFF_SOME?", inputsChanged || resourcesChanged || outputsChanged)
println("inputsChanged?", inputsChanged)
println("resourcesChanged?", resourcesChanged)
println("outputsChanged?", outputsChanged)

if inputsChanged || resourcesChanged || outputsChanged {
resp := &pulumirpc.DiffResponse{
Changes: pulumirpc.DiffResponse_DIFF_SOME,
}
if len(replaceKeys) > 0 {
resp.Replaces = replaceKeys
resp.DeleteBeforeReplace = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeleteBeforeReplace gets past the error! Promising!

}
return resp, nil
}

// the module has not changed, return DIFF_NONE.
Expand Down
Loading