-
Notifications
You must be signed in to change notification settings - Fork 44
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
Detailed diff does not mark fully computed properties for recomputation when the resource is replaced #2660
Comments
Can we have a fully worked example here to help understand impact? Thanks! |
I've added an example to the description, thanks for flagging that up. |
Looked up what Opentofu does here: https://github.com/opentofu/opentofu/blob/864aa9d1d629090cfc4ddf9fdd344d34dee9793e/internal/tofu/node_resource_abstract_instance.go#L1054 Looks like they re-plan the change with a nil prior if they detect a replace in order to re-computed computed properties. I'll attempt something similar for Diff. Wondering if this also affects Update - should Update re-plan the output once we detect a replace. Opened #2672 to follow up on what happens in Update |
Can the example include the before and after program indicating which state transition this is in? |
From the information so far it appears that this is a cosmetic opportunity for improvement but not necessarily a deal breaker (e.g. Pulumi correctly indicates the replace) and the only issue is that Pulumi is a bit overconfident about these computed attributes which might in fact change. Does that sound about right? |
Yeah, it is also a regression in PF as it previously did detect these changes and displayed them to the user. Is it possible that this also affects correctness? What if another resource depends on this property and we do not mark it as possibly Unknown? Would the dependent resource always get updated too, even if we indicate that the property it depends on does not change? I opened #2672 to potentially follow-up on that Do you think we should backlog this? |
Discussed offline. We decided this is indeed a blocker as it affects the preview of all Computed properties and they have regressed compared to not using detailed diff v2. It is also a pre-existing bug in SDKv2, so affects quite a few resources. |
Attempted to solve this the same way that opentofu does, by re-planning the value with a nil prior after detecting a replace. Unfortunately, we seem to be running into engine - provider protocol limitations: For the example above and the following detailed diff:
we get the following preview:
which is not correct. Notice that id is marked for deletion instead of update to I believe this is because the engine is using the values from old state and new inputs for showing the detailed diff. This is wrong because the new inputs have no values for fully computed properties, so we get a delete instead of an Update to UNKNOWN. An interesting question here is how does the engine display this correctly when no detailed diff is returned from Diff. Perhaps it is using the output of Update(preview=true), so the question becomes why does it not use that when a detailed diff is returned from Diff. EDIT: Found something in the step_generator which might be responsible for marking computed values as unknown: https://github.com/pulumi/pulumi/blob/8314293d6e9901c747b0d397eff9a4a0c0e00466/pkg/resource/deploy/step_generator.go#L2120 That iterates, however, on the inputs, not outputs, so might not be the right thing which does this. |
This PR adds Diff cross-tests for the SDKv2 bridge to test the re-computation of computed properties when the resource is marked for replacement. We display an incorrect preview in such cases in the PF and this also affects the SDKv2. related to #2660
Found some indication in the engine that this might have been considered before: The engine re-runs Check if Diff indicates a resource is going to be replaced. |
Here is a branch where we do this re-planning: #2673 It shows the effect on the previews and the wrong display of deletions of computed resources. |
This is blocked on #2281 or something equivalent which gives the engine access to the planned outputs. Alternatively, there might be a solution where the engine works around the issue and marks Output-only properties as unknown on replace, like it does when no detailed diff is returned from Diff |
This change disables accurate previews for the PF tests as accurate preview rollout for PF is blocked on #2660 The first commit here are the code changes and the second one is test recordings.
Fully computed properties (like ID) do not get marked as unknown in previews which suggest a replace. This leads to an incorrect preview as the value will most likely change.
@Frassle also noted that the diff output is used for update plans, so this is not purely presentational either. It is also likely that the #2672 affects previews where there is another resource which depends on this fully computed property.
Example:
If we transition from:
properties: {}
toproperties: {key: "value"}
for the PF schemaWe get:
versus
Notice that we do not flag the ID property as changing but TF does. We should as well, since if the resource is replaced, all computed properties will get re-computed.
Note that a similar issue arises in SDKv2 where this is a pre-existing bug.
See
TestDetailedDiffStringAttribute/replace/added
The text was updated successfully, but these errors were encountered: