-
Notifications
You must be signed in to change notification settings - Fork 43
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
Add SDKv2 Detailed Diff tests for Computed properties in sets #2740
Add SDKv2 Detailed Diff tests for Computed properties in sets #2740
Conversation
This change is part of the following stack: Change managed by git-spice. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2740 +/- ##
=======================================
Coverage 68.60% 68.60%
=======================================
Files 322 322
Lines 41223 41223
=======================================
Hits 28282 28282
Misses 11348 11348
Partials 1593 1593 ☔ View full report in Codecov by Sentry. |
7c0b26d
to
d7e5748
Compare
7c5f7c4
to
d8b1526
Compare
d7e5748
to
9ce613b
Compare
d8b1526
to
bd80587
Compare
bd80587
to
8afffe0
Compare
8afffe0
to
8f2b3d6
Compare
995278d
to
edbbf6c
Compare
8f2b3d6
to
23ca148
Compare
Mark it ready for review when ready 🙏 |
cede42b
to
ee3ff32
Compare
23ca148
to
983e8df
Compare
ee3ff32
to
6c8be27
Compare
fc613aa
to
f64719e
Compare
9d2b6a5
to
1310b4d
Compare
f64719e
to
9c9e1d3
Compare
1310b4d
to
3504da5
Compare
9c9e1d3
to
4ea302c
Compare
3504da5
to
c99f64d
Compare
c99f64d
to
4c3deba
Compare
fed65d6
to
8e6731f
Compare
6e6a723
to
fff242e
Compare
fff242e
to
eae4813
Compare
… set inputs to plan (#2761) This PR reworks the way we compute the detailed diff for set type elements in order to handle sets with computed properties better. ## Context There are two reasons it is challenging to produce the detailed diff for set type properties: - The planning process re-orders the elements of a set. - The engine does not have access to the post-plan properties but can only display diff previews in terms of `OldState` and `NewInputs`. These two reasons means that once we compute the detailed diff in terms of `OldState` to `PlannedState`, we need to do a bit of work to transform it into a diff in terms of `OldState` and `NewInputs`. Matching `PlannedState` values to `NewInputs` values is especially challenging for elements which contain `Computed` properties as these can change during the planning process. The previous implementation used the hashes of set elements to do the matching but that completely failed for set elements with `Computed` properties, as the `Computed` property will change the hash. ## New implementation This implementation instead uses [a technique](https://github.com/opentofu/opentofu/blob/cb2e9119aa75eeb8e1fa175e2b7a205a4fef129f/internal/plans/objchange/objchange.go#L433) borrowed from opentofu, which is used for a similar purpose. We now do a fuzzy match on the `PlannedState` value to the `NewInputs` value, which allows for differences in `Computed` properties. Non-`Computed` properties still need to match exactly. ## Example For the schema ``` "foo": Set{ Elem: { "bar": {Type: string, Optional: true} "baz": {Type: string, Computed: true} } } ``` and the inputs `[{bar: val1}, {bar: val2}]` changing to `[{bar: val1}, {bar: val3}]` we might observe the plan becoming `[{bar: val3, baz: comp3}, {bar: val1, baz: comp1}]` We now need to correctly match the elements to their corresponding inputs, in order to correctly communicate the diff to the engine in terms of `OldState` and `NewInput`: `{bar: val3, baz: comp3}` should match `{bar: val3}` (the second element in the input) and `{bar: val1, baz: comp1`} should match `{bar: val1}` ## Testing I've added additional integration tests around `Computed` in #2740 as well as unit tests here. I'll annotate any left-over issues in the recorded tests to be resolved. Changes up to [4ba30d9](4ba30d9) have the code changes and [4ba30d9](4ba30d9) has the test recordings. ## Release Note that this is feature flagged behind Accurate Previews fixes #2652 fixes #2528
This PR has been shipped in release v3.99.0. |
This PR adds tests around Computed properties in Sets for SDKv2, similar to what we have on the PF side.
set attributes:
For the block tests each test has a variant with the computed property unspecified in the program and one where the property is specified in the user program.
set blocks:
Note that all these tests are currently run without Accurate Previews, because of #2528. I will enable the Accurate Previews feature flag for these tests along with the fix for 2528, so that we can evaluate the differences compared to not running the feature flag.
The output is non-deterministic without Accurate Previews, so the tests are recorded but skipped.
necessary for #2528