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

Example of using auto mapper #435

Closed
wants to merge 2 commits into from
Closed

Example of using auto mapper #435

wants to merge 2 commits into from

Conversation

t0yv0
Copy link
Member

@t0yv0 t0yv0 commented Dec 5, 2022

This would require a fix not yet in pulumi/pulumi: pulumi/pulumi#11537

Yet it may be promising - the code for converting between the typed model (Image, Build) and resource.PropertyValue can be automated via the mapper package - the boilerplate can be removed or reduced.

@github-actions
Copy link

github-actions bot commented Dec 5, 2022

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

@t0yv0
Copy link
Member Author

t0yv0 commented Dec 6, 2022

Eh, this is an interesting exercise but not sure it's paying its weight. Using the mapper trips over inability to express the unions here like bool | CacheFrom cleanly. Working around is pretty verbose.

On the upside, using the mapper automatically checks that required field are set and provides warnings appropriately. It could also complain about fields it does not understand, if they are being set but cannot be parsed cleanly.

@guineveresaenger
Copy link
Contributor

This may be a reason to drop existing unions from the provider, although it would lock us into never having any:

#428
#427

@t0yv0
Copy link
Member Author

t0yv0 commented Dec 6, 2022

I think unions are still a feature out there in the wild world of schemas. I'd keep this around w/o merging for a bit as something that informs the design of mapper module. Perhaps there's a trick we could teach mapper to do that would make working with unions more reasonable.

@AaronFriel
Copy link
Contributor

@t0yv0 @guineveresaenger I think we can close this draft?

@t0yv0
Copy link
Member Author

t0yv0 commented Feb 6, 2023

Up to @guineveresaenger - I've not been up-to-date with latest docker changes, but strategically this still makes a lot of sense to me to finish up to make more custom resource development sustainable, so it should go on the backlog somewhere? That is:

  • upstream improved serde facilities (PropertyValue <-> typed structs) into pulumi/pulumi/sdk
  • use automatic serde instead of manual serializers

Automatic code is less error prone, easier to read and can be made to more predictably handle missing values with localized error messages. Manually written code typically misses an error case here or there.

I'm wondering though if there's something in the new-style provider SDK that can be used for this purpose instead of the automapper module from sdk/v3.

@t0yv0
Copy link
Member Author

t0yv0 commented Feb 13, 2023

Ah I see the request is tracked in pulumi/pulumi#11530 so that's good. Possibly need to put it on x-team request list. Without MarshalJSON/UnmarshalJSON style hooks in the automapper this is not practical.

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.

3 participants