pulumi / pulumi-terraform-bridge

A library allowing Terraform providers to be bridged into Pulumi.
Apache License 2.0
194 stars 43 forks source link

Support referencing custom schema types with the TF plugin framework provider #977

Open frezbo opened 1 year ago

frezbo commented 1 year ago

Issue details

When using TF resources with nested attributes common between resources (input/output), the auto-generated schema defines a custom type per resource meaning resource outputs cannot be directly referenced as inputs without writing complex mapping functions.

Allow setting custom types.

932 allowed setting custom types, but the types cannot be referenced in resources/data sources yet

t0yv0 commented 1 year ago

Thank you for this feature request!

Just to clarify specifically you would like to add an entry in ProviderInfo.ExtraTypes and then reference this type in resource declaration? Do you have any source pointers (perhaps pre-Plugin Framework) that would be very helpful.

Searching Pulumi org I find instances of ExtratTypes use e.g here:

https://github.com/pulumi/pulumi-digitalocean/blob/57a6d83eac66ac62db2bf261897041045d430a96/provider/resources.go#L293

But it's a surprise this doesn't not work on top of Plugin Framework (yet), my understanding is it should have worked. We'll have to verify.

frezbo commented 1 year ago

But it's a surprise this doesn't not work on top of Plugin Framework (yet)

correct, there's validation here https://github.com/pulumi/pulumi-terraform-bridge/blob/master/pf/tfgen/not_supported.go#L102

Just to clarify specifically you would like to add an entry in ProviderInfo.ExtraTypes and then reference this type in resource declaration?

correct, this would still certainly be a hack since pulumi creates go types based on resource name. For example:

This is just after converting to use the TF provider migrated to Plugin Framework

all these are exactly same type fields internally, but when sdk is generated these resources cannot be referenced directly as in Terraform needing multiple functions to convert between these types. Also some being resources and some being data sources makes it very hard to reference these since it involves a lot of .ApplyT lifting hackery

frezbo commented 1 year ago

Another option would be a way to specify common types in different resources so that the schema generates a common one and not prefixed with the resource name