Skip to content

Conversation

@VenelinMartinov
Copy link
Contributor

@VenelinMartinov VenelinMartinov commented Jul 23, 2024

We seem to represent list-nested objects in the shim layer differently depending on if it is an attr or block.
The attribute one seems overly complicated: list: {element: schema: element: resource} vs list: element: resource for blocks.

This is an attempt at simplifying it - not fully tested yet.

@VenelinMartinov VenelinMartinov changed the base branch from master to vvm/add_pf_shim_tests1 July 23, 2024 10:27
@VenelinMartinov
Copy link
Contributor Author

The failing tests even expects this:

assert.Truef(t, isPseudoResource, "expected shim.Elem() to be of type shim.Resource, encoding an object type")

It says it asserts on type .Resource but actually asserts on .Schema

@codecov
Copy link

codecov bot commented Jul 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 56.44%. Comparing base (19697fa) to head (8322504).

❗ There is a different number of reports uploaded between BASE (19697fa) and HEAD (8322504). Click for more details.

HEAD has 43 uploads less than BASE
Flag BASE (19697fa) HEAD (8322504)
64 21
Additional details and impacted files
@@                          Coverage Diff                           @@
##           vvm/tfgen_name_override_bug_repro    #2232       +/-   ##
======================================================================
- Coverage                              67.48%   56.44%   -11.05%     
======================================================================
  Files                                    325      305       -20     
  Lines                                  41633    40393     -1240     
======================================================================
- Hits                                   28096    22798     -5298     
- Misses                                 11957    15927     +3970     
- Partials                                1580     1668       +88     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@t0yv0 t0yv0 self-requested a review July 23, 2024 14:57
Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this change is correct. I'm extremely surprised there are not runtime implications to this.

@VenelinMartinov
Copy link
Contributor Author

I believe we must have been already handling both as both are present. I'll sit on this for a bit

assert.Equal(t, shim.TypeList, shimmed.Type())
assert.NotNil(t, shimmed.Elem())
_, isPseudoResource := shimmed.Elem().(shim.Schema)
_, isPseudoResource := shimmed.Elem().(shim.Resource)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert on next line interestingly said it expects Resource, but the cast is casting to shim.Schema.

@t0yv0
Copy link
Member

t0yv0 commented Jul 23, 2024

This may be a better encoding, but this is pretty error-prone, I wonder if we could complement this with some tests taking this for a spin end to end. Specifically, for tfgen layer and runtime handling:

  • is the Pulumi schema generated for these resources what we expect?
  • can the bridged provider actually push data through and have it decoded in the PF Create method to match the shape expected by PF

@t0yv0
Copy link
Member

t0yv0 commented Jul 23, 2024

Also sounds like an update on the Elem() doc comment is needed here for this case.

@VenelinMartinov
Copy link
Contributor Author

Yeah, some end-to-end tests are certainly needed - thanks for the suggestions on what to focus on!

I'll also revisit the Elem docs.

@t0yv0
Copy link
Member

t0yv0 commented Jul 24, 2024

I expect there is a big encoding bug here somewhere.

Map-nested attributes Map<string,{"x":string}> and single-nested blocks {"x":string} don't have enough in shim.Schema to distinguish them:

https://developer.hashicorp.com/terraform/plugin/framework/handling-data/attributes/map-nested

But they might clobber each other in the shim.Schema representation with Type=TypeMap, Elem()=Resource.

Also in SDKv2 TypeMap, Elem()=Resource means a degenerate case of Map<string,string>. Ideally we cover all these cases and get this right.

@VenelinMartinov
Copy link
Contributor Author

Also in SDKv2 TypeMap, Elem()=Resource

This is invalid in SDKv2 - only lists and sets can have an Elem Resource

@t0yv0
Copy link
Member

t0yv0 commented Jul 24, 2024

IT is admitted though, and valid, per doc in Elem() and https://github.com/hashicorp/terraform-plugin-sdk/blob/main/helper/schema/core_schema_test.go#L220

@VenelinMartinov
Copy link
Contributor Author

@VenelinMartinov
Copy link
Contributor Author

Wondering if any providers actually use this - I doubt it works well

@t0yv0
Copy link
Member

t0yv0 commented Jul 24, 2024

We have to make it an error though, or else to make the schema Map<string,string>, since it's a possibility.

@VenelinMartinov
Copy link
Contributor Author

Yeah, absolutely, great point about Map nested Resource elems in SDKv2

@mjeffryes mjeffryes added this to the 0.108 milestone Aug 16, 2024
@mikhailshilkov mikhailshilkov removed this from the 0.108 milestone Aug 21, 2024
@t0yv0
Copy link
Member

t0yv0 commented Oct 1, 2024

AS time permits, could we rebase on #2456 and have another peek at the interesting bits with the generated Pulumi Schema side-by-side? Could be a good learning experience. Thanks!

@VenelinMartinov
Copy link
Contributor Author

VenelinMartinov commented Jan 23, 2025

@VenelinMartinov VenelinMartinov changed the base branch from master to vvm/tfgen_name_override_bug_repro January 23, 2025 13:31
@VenelinMartinov VenelinMartinov force-pushed the vvm/simplify_pf_attr_obj_shim branch from 5253750 to 9617124 Compare January 23, 2025 13:31
@VenelinMartinov VenelinMartinov mentioned this pull request Jan 23, 2025
@VenelinMartinov VenelinMartinov force-pushed the vvm/simplify_pf_attr_obj_shim branch from ba46990 to 071d00c Compare January 23, 2025 13:40
@VenelinMartinov VenelinMartinov force-pushed the vvm/simplify_pf_attr_obj_shim branch 2 times, most recently from 6cf0650 to ad04b40 Compare January 23, 2025 13:54
@VenelinMartinov VenelinMartinov force-pushed the vvm/simplify_pf_attr_obj_shim branch from ad04b40 to 8322504 Compare January 23, 2025 14:03
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.

5 participants