-
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
Normalize block values before passing to TF provider #1971
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1971 +/- ##
==========================================
- Coverage 63.31% 61.51% -1.80%
==========================================
Files 333 334 +1
Lines 37405 45035 +7630
==========================================
+ Hits 23682 27704 +4022
- Misses 12198 15802 +3604
- Partials 1525 1529 +4 ☔ 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 |
Verified that |
Let's check that |
I've extracted the unknown tests in #2054 There are some failures in the new code related to unknowns - I'll address these next. Appreciate the input here 🙏 Should be fixed - we no longer panic on unknown collections - instead we return the unknown as is. |
@@ -5484,7 +5484,7 @@ func TestPlanResourceChangeUnknowns(t *testing.T) { | |||
"maxItemsOneProp":null, | |||
"setBlockProps":[], | |||
"listBlockProps":[], | |||
"nestedListBlockProps":[{"nestedProps":null}], | |||
"nestedListBlockProps":[{"nestedProps":[]}], |
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 is the only change in behaviour to current master related to unknowns and it seems reasonable to me - nestedProps is a list type so should not be nil.
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.
Yeah looks like MakeTerraformInputs substituted "04da6b54-80e4-46f7-96ec-b56ff0331ba9" into "nestedListBlockProps":[{"nestedProps":null}],
and then the newly added pass corrected that to []
. This is fine.. we're already in heuristic land in this case. Good to have it covered!!
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: typeList or typeSet with a Resource Elem.
fixes #1970
fixes #1915
fixes #1964
fixes #1767
fixes #1762
TODO: [DONE] remove the MaxItemsOne default hacks introduced in #1725 (opened #2049)