Skip to content
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

Merged
merged 6 commits into from
Dec 18, 2024

Conversation

VenelinMartinov
Copy link
Contributor

@VenelinMartinov VenelinMartinov commented Dec 12, 2024

This PR adds tests around Computed properties in Sets for SDKv2, similar to what we have on the PF side.

set attributes:

  • with computed
  • with computed and force new

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:

  • with computed at the top level
  • with computed at the top level and ForceNew at the top level
  • with computed at the top level and a nested ForceNew
  • with computed at the nested level
  • with computed at the nested level and ForceNew at the top level
  • with computed at the nested level and a nested ForceNew

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

Copy link

codecov bot commented Dec 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.60%. Comparing base (b337517) to head (ab20960).
Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

@VenelinMartinov VenelinMartinov marked this pull request as draft December 12, 2024 15:40
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_lists_many_elements branch from 7c0b26d to d7e5748 Compare December 13, 2024 16:33
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_computed_in_sets branch from 7c5f7c4 to d8b1526 Compare December 13, 2024 16:34
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_lists_many_elements branch from d7e5748 to 9ce613b Compare December 13, 2024 17:42
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_computed_in_sets branch from d8b1526 to bd80587 Compare December 13, 2024 17:42
Base automatically changed from vvm/sdkv2_detailed_diff_lists_many_elements to master December 13, 2024 19:17
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_computed_in_sets branch from bd80587 to 8afffe0 Compare December 16, 2024 11:38
@VenelinMartinov VenelinMartinov changed the base branch from master to vvm/return_detailed_diff_only_if_diff_some December 16, 2024 11:39
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_computed_in_sets branch from 8afffe0 to 8f2b3d6 Compare December 16, 2024 11:39
@VenelinMartinov VenelinMartinov force-pushed the vvm/return_detailed_diff_only_if_diff_some branch from 995278d to edbbf6c Compare December 16, 2024 11:57
@VenelinMartinov VenelinMartinov changed the base branch from vvm/return_detailed_diff_only_if_diff_some to vvm/sdkv2_detailed_diff_replace_tests December 16, 2024 12:00
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_computed_in_sets branch from 8f2b3d6 to 23ca148 Compare December 16, 2024 12:00
@t0yv0
Copy link
Member

t0yv0 commented Dec 16, 2024

Mark it ready for review when ready 🙏

@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_replace_tests branch from cede42b to ee3ff32 Compare December 16, 2024 15:50
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_computed_in_sets branch from 23ca148 to 983e8df Compare December 16, 2024 15:50
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_replace_tests branch from ee3ff32 to 6c8be27 Compare December 16, 2024 15:51
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_replace_tests branch from fc613aa to f64719e Compare December 17, 2024 09:37
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_computed_in_sets branch from 9d2b6a5 to 1310b4d Compare December 17, 2024 09:37
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_replace_tests branch from f64719e to 9c9e1d3 Compare December 17, 2024 09:49
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_computed_in_sets branch from 1310b4d to 3504da5 Compare December 17, 2024 09:49
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_replace_tests branch from 9c9e1d3 to 4ea302c Compare December 17, 2024 09:55
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_computed_in_sets branch from 3504da5 to c99f64d Compare December 17, 2024 09:55
Base automatically changed from vvm/sdkv2_detailed_diff_replace_tests to master December 17, 2024 14:34
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_computed_in_sets branch from c99f64d to 4c3deba Compare December 17, 2024 15:09
@VenelinMartinov VenelinMartinov marked this pull request as ready for review December 17, 2024 19:17
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_computed_in_sets branch from fed65d6 to 8e6731f Compare December 17, 2024 19:22
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_computed_in_sets branch 2 times, most recently from 6e6a723 to fff242e Compare December 18, 2024 10:07
@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_detailed_diff_computed_in_sets branch from fff242e to eae4813 Compare December 18, 2024 10:14
@VenelinMartinov VenelinMartinov merged commit 0afd418 into master Dec 18, 2024
17 checks passed
@VenelinMartinov VenelinMartinov deleted the vvm/sdkv2_detailed_diff_computed_in_sets branch December 18, 2024 14:15
VenelinMartinov added a commit that referenced this pull request Dec 23, 2024
… 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
@pulumi-bot
Copy link
Contributor

This PR has been shipped in release v3.99.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants