-
Notifications
You must be signed in to change notification settings - Fork 40
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
Normalize block values before passing to TF provider #1971
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1971 +/- ##
==========================================
+ Coverage 61.39% 61.40% +0.01%
==========================================
Files 334 334
Lines 44950 45020 +70
==========================================
+ Hits 27595 27644 +49
- Misses 15829 15844 +15
- Partials 1526 1532 +6 ☔ View full report in Codecov by Sentry. |
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.
Good test case to add, continues to be surprising.
Pretty sure this is happening in the else block here: pulumi-terraform-bridge/pkg/tfshim/sdk-v2/cty.go Lines 220 to 233 in 7aa41da
|
attrs[attrName] = cty.NullVal(attrType) is a correct representation AFAIK, digging in. |
In the cross tests this is flagged as a diff:
|
Yeah this is plausible.
Perhaps this comes back to the fact that null values aren't representable in TF for set-nested blocks. Therefore it's an automatic empty set aka |
Yeah and I think this is were it gets really messy with SchemaConfigMode, since they are representable if ConfigModeAttr is set. |
I ran into some trouble with |
True - this is just saying the fix need to accommodate both for both cases:
I tried a quick fix quickly - sorry accidentally pushed a commit to this branch. Meant a separate branch I can get the quick fix to pass RawConfig test but curiously NOT the RawPlan test. This makes me wonder what's going on there. Could this be because we'e linking in outdated code for planning the change compared to TF CLI? It's a bit unfortunate that in this test setup we cannot debug into TF CLI to see what is it doing . |
I'd also wager my fix doesn't cut it for the attribute case which might need to actually return |
BTW the reason this may be less impactful than it seems is that few providers consult RawPlan and RawConfig on Create, they mostly consult the ResourceData. So issues of this sort remain unfixed. |
I think the attribute case is completely unhandled but let's fix that seprately. Isn't there the same issue in
|
Well that one looks fine? hcty2ctyWithType converts between two equivalent representations cty.Value and hcty.Value, converting null to null is reasonable, why do we have null passed into that in the first place would be the question? Perhaps we need to fix at the level of MakeTerraformInputs? What is not yet tested that's really interesting to test, even more fundamentally important than RawConfig/RawPLan parity, is whether the two paths get the same answer to this:
|
I believe I found two other places where the state is populated with nulls instead of empty collections:
and
The first one is fairly straight-forward to fix but the upgradeState stuff might be better fixed by calling a higher level function in the plugin-sdk -it looks to me like we are doing multiple passes back and forth between instanceState and cty values both in the bridge code and then in the plugin-sdk. Investigating... |
Fairly sure we are loosing the value here:
the which is then converted to |
Ah, I think we are missing a null normalization after calling In the plugin-sdk: https://github.com/hashicorp/terraform-plugin-sdk/blob/70fb6b9b15e8e5fc73f424e24084c28fedd1e013/helper/schema/grpc_provider.go#L1100-L1106
But in
we don't then normalize the nulls to empty collections after calling |
extracted from #1971 This adds tests for ConfigModeAttr, Timeout and nested blocks. `SkipCompareRawConfig` is used for the parts which need 1971
Most of the downstream updates which weren't there before look like #2047 Empty maps refresh dirty now. EDIT: Actually this is present on master too. The type checking test failures are not significant as the tests assert on the exact panic message - not meaningful here. The other test failures are also issues with the tests, not the changes. The downstream failures look like they are all present on master as well. I believe this is good to go now. Kicking off another round of downstream tests from 4f24fa4 |
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.
I'm exited to get this in. If the downstream tests go well, does that mean we are ready to merge?
Yeah, the PR should be good to go if downstream tests pass. |
Co-authored-by: Ian Wahbe <[email protected]>
Tested pulumi-aws after the ComputeID fixes - it flaked on one test but is otherwise fine: https://github.com/pulumi/pulumi-aws/actions/runs/9350339814/job/25736323726?pr=4012 I think this is good to go. I've seen to failures in downstream tests aside from the repos with ComputeID issues. |
pkg/tfshim/sdk-v2/provider2.go
Outdated
func normalizeIterable(blockVal cty.Value, blockRes *schema.Resource) []cty.Value { | ||
contract.Assertf(blockVal.Type().IsListType() || blockVal.Type().IsSetType(), | ||
"normalizeIterable: Expected list or set type, got %v", blockVal.Type().GoString()) | ||
if blockVal.IsNull() || !blockVal.IsKnown() { |
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.
Are we certain about the !blockVal.IsKnown()
case? This seems like a bigger deal. Tested this well?
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.
I've opened #2032 to follow up with an investigation of unknown blocks, which is inexpressible in TF.
It should not happen but if it does we can't do anything about it in that function, so I've opted to keep it as is for now.
I would like to understand test coverage here at the integration level. Something changed with the cross-tests, perhaps for the better, but it's not visible in the diff. Can we get a summary? Perhaps double up on some of these with targeted test cases? fixes #1970 The most worrisome case to me is replacing unknowns with empty collections, basically testing this at an integration level, since I believe we have several subsystems fighting over it (MakeTerraformInputs, and now normalizeCollections). Can we find out how the bridged provider behavior is changing in that case, and importantly, why, is this what we want? #1885 related here but might not be the end of the story. |
part of #1785
This change adds a normalisation step for collections when recovering cty values to pass to terraform. This ensures we represent them similarly to terraform.
In practice this means that all block collections need to be passed to TF providers as an empty collection instead of nil. This should get rid of quite a few subtle discrepancies in the data we pass to the TF provider code. These sometimes result in panics since we pass unexpected nils.
This gets rid of all known input discrepancies discovered so far through cross-testing.
The full rules for what is a block are here. It is essentially properties with schema: type List or Sets with a Resource Elem.
fixes #1970 (TestInputsEmptyCollections and TestInputsNestedBlocksEmpty)
fixes #1915 (TestInputsEmptyCollections and TestInputsNestedBlocksEmpty)
fixes #1964 (TestInputsEmptyCollections and TestInputsNestedBlocksEmpty)
fixes #1767 (TestInputsEmptyCollections and TestInputsNestedBlocksEmpty)
fixes #1762 (TestInputsConfigModeEqual)
TODO: [DONE] remove the MaxItemsOne default hacks introduced in #1725 (opened #2049)