pulumi / pulumi-terraform-bridge

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

Refactor Main entry-points #1487

Open t0yv0 opened 1 year ago

t0yv0 commented 1 year ago

We currently have a proliferation of entry-point functions for bridged providers, both for the provider itself and for the helper tfgen binary.

For the provider itself:

For the tfgen binary:

There's a couple of issues here. First it's confusing to users. It's also a bit of a maintenance burden to keep initialization logic in sync. Finally there is a small issue with tracing initialization time calls - a lot of provider runtimes bottom out at https://github.com/pulumi/pulumi/blob/master/pkg/resource/provider/main.go#L38 which installs tracing but it is happening too late with respect to heavy-hitting init logic such as aliasing computations (https://github.com/pulumi/pulumi-gcp/blob/t0yv0%2Fupgrade-tests-take2/provider/resources.go#L387 Provider function for example is heavy but is currently called before tracing is initialized).

Consider figuring out how we can refactor to this to encourage one single Main entrypoint, deprecate the others while still supporting them, and ensure that for the provider itself heavy init happens inside provMaker func(*HostClient) (pulumirpc.ResourceProviderServer, error) so that the initialization sequence is as-intended.

t0yv0 commented 1 year ago

There's a bit of a design exercise on how the refactored main for providers should look like to minimize disruption.

We have this:

func Main(pkg string, version string, prov ProviderInfo, pulumiSchema []byte, opts ...Option) {

For larger providers would like to passfunc () ProviderInfo instead lazily.

We could work with the existing Option pattern. We could enable this by:

Main("gcp", "7.0.0", ProviderInfo{}, schema, WithProviderInfoBuilder(func () ProviderInfo { ... }))
iwahbe commented 1 year ago

If we're willing to migrate, I would love to have Main(func(ctx context.Context) (name string, _ ProviderInfo)). At the very least, we should pass context.Context.

iwahbe commented 1 year ago

Note: To unify the pkg/tfbridge and pf/tfbridge entry point, we would need to introduce a new package or merge https://github.com/pulumi/pulumi-terraform-bridge/issues/1445.