-
Notifications
You must be signed in to change notification settings - Fork 1
WIP: try to bubble up resource replacements to module replacements #425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
inputsChanged = true | ||
} | ||
|
||
// Here, inputs have not changes but the underlying module might have changed | ||
|
@@ -142,7 +142,7 @@ func (h *moduleHandler) Diff( | |
tf, err := h.prepSandbox( | ||
ctx, | ||
urn, | ||
oldInputs, | ||
newInputs, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks suspect! Why the change. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
There was a problem hiding this comment.
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.