Repository: pulumi/pulumi-terraform-bridge
Pull request #1062 (2023-05-01 17:14:52)

[Muxer] Update and standardize public API
This change is necessary because some providers have a different `provider` argument then their `ProviderInfo.Name` value. The previous API assumed they were the same.

github-actions[bot]: Diff for [pulumi-azuread](https://github.com/pulumi-bot/pulumi-azuread/compare/809f0d3..a9ec75e) with merge commit 62652783eca7a176f7ec542e28f92fede5573863
github-actions[bot]: Diff for [pulumi-random](https://github.com/pulumi-bot/pulumi-random/compare/eb17444..675ffa0) with merge commit 62652783eca7a176f7ec542e28f92fede5573863
github-actions[bot]: Diff for [pulumi-gcp](https://github.com/pulumi-bot/pulumi-gcp/compare/d04b91fc5..923419368) with merge commit 62652783eca7a176f7ec542e28f92fede5573863
github-actions[bot]: Diff for [pulumi-azure](https://github.com/pulumi-bot/pulumi-azure/compare/ae8e6f084..0630748fb) with merge commit 62652783eca7a176f7ec542e28f92fede5573863
t0yv0: This can be a fine change but PF also assumes these names are the same.  

So to dig a littler further. DO they really have to be different?

Which providers are affected? 

I checked pulumi-gcp. We have "gcp"  as name but ProviderInfo.Name has "google-beta" - is that the one known use case or do we have more? Should this just be fixed? "google-beta" sounds off, should it be fixed to "gcp" I that provider? I'm wondering what's the "by-design" distinction between the two names. It doesn't seem like we have it documented so it's possible to trip over it.


t0yv0: Umm, yes, ProviderInfo.Name is documented as this, and is probably legitimately different from the bridged provider name. IN this case LGTM but we'll need the same fix to non-muxed variant of PF providers.

```
	Name          string        // the TF provider name (e.g. terraform-provider-XXXX).
```
iwahbe: @t0yv0 Are you sure that PF also makes this assumption? PF based `Main` functions take a name string:

https://github.com/pulumi/pulumi-terraform-bridge/blob/5513a5246d101e79640e79a942c6dd95deafac31/pf/tfbridge/main.go#L38

https://github.com/pulumi/pulumi-terraform-bridge/blob/5513a5246d101e79640e79a942c6dd95deafac31/pf/tfgen/main.go#L38
t0yv0: You're right, should have checked. Seems OK! Thank you.
github-actions[bot]: Diff for [pulumi-random](https://github.com/pulumi-bot/pulumi-random/compare/bb092ac..0b71996) with merge commit 18ee84d3c71a05b77bf4d0f8491f2eaaef4197ca
github-actions[bot]: Diff for [pulumi-azuread](https://github.com/pulumi-bot/pulumi-azuread/compare/ba9ead9..8fc2c27) with merge commit 18ee84d3c71a05b77bf4d0f8491f2eaaef4197ca

Patch:
diff --git a/pf/tfbridge/main.go b/pf/tfbridge/main.go
index 472d21b6..0e33b102 100644
--- a/pf/tfbridge/main.go
+++ b/pf/tfbridge/main.go
@@ -101,15 +101,15 @@ func handleFlags(
 // Implements main() or a bridged Pulumi plugin, complete with argument parsing.
 //
 // This is an experimental API.
-func MainWithMuxer(ctx context.Context, schema []byte, info tfbridge.ProviderInfo) {
+func MainWithMuxer(ctx context.Context, pkg string, info tfbridge.ProviderInfo, schema []byte) {
 	handleFlags(ctx, info.Version, func() (*tfbridge.MarshallableProviderInfo, error) {
 		info := info
 		return tfbridge.MarshalProviderInfo(&info), nil
 	})
 
-	f := MakeMuxedServer(ctx, schema, info)
+	f := MakeMuxedServer(ctx, pkg, info, schema)
 
-	err := rprovider.Main(info.Name, f)
+	err := rprovider.Main(pkg, f)
 	if err != nil {
 		cmdutil.ExitError(err.Error())
 	}
@@ -120,7 +120,7 @@ func MainWithMuxer(ctx context.Context, schema []byte, info tfbridge.ProviderInf
 // This function exposes implementation details for testing. It should not be used outside
 // of pulumi-terraform-bridge.  This is an experimental API.
 func MakeMuxedServer(
-	ctx context.Context, schema []byte, info tfbridge.ProviderInfo,
+	ctx context.Context, pkg string, info tfbridge.ProviderInfo, schema []byte,
 ) func(host *rprovider.HostClient) (pulumirpc.ResourceProviderServer, error) {
 
 	shim, ok := info.P.(*pfmuxer.ProviderShim)
@@ -142,7 +142,7 @@ func MakeMuxedServer(
 		marshalled := tfbridge.MarshalProviderInfo(&info)
 		data, err := json.Marshal(marshalled)
 		return muxer.GetMappingResponse{
-			Provider: info.Name,
+			Provider: pkg,
 			Data:     data,
 		}, err
 	}
@@ -170,10 +170,10 @@ func MakeMuxedServer(
 			default:
 				m.Servers = append(m.Servers, muxer.Endpoint{
 					Server: func(host *rprovider.HostClient) (pulumirpc.ResourceProviderServer, error) {
-						return tfbridge.NewProvider(ctx, host, info.Name, version, prov, info, schema), nil
+						return tfbridge.NewProvider(ctx, host, pkg, version, prov, info, schema), nil
 					}})
 			}
 		}
-		return m.Server(host, info.Name, version)
+		return m.Server(host, pkg, version)
 	}
 }
diff --git a/pf/tfgen/main.go b/pf/tfgen/main.go
index ba99a294..cc4a1af7 100644
--- a/pf/tfgen/main.go
+++ b/pf/tfgen/main.go
@@ -73,11 +73,11 @@ func Main(provider string, info tfbridge.ProviderInfo) {
 // This is an experimental API.
 //
 // [Pulumi Package Schema]: https://www.pulumi.com/docs/guides/pulumi-packages/schema/
-func MainWithMuxer(info sdkBridge.ProviderInfo) {
+func MainWithMuxer(provider string, info sdkBridge.ProviderInfo) {
 	shim, ok := info.P.(*pfmuxer.ProviderShim)
 	contract.Assertf(ok, "MainWithMuxer must have a ProviderInfo.P created with AugmentShimWithPF")
 
-	tfgen.MainWithCustomGenerate(info.Name, info.Version, info, func(opts tfgen.GeneratorOptions) error {
+	tfgen.MainWithCustomGenerate(provider, info.Version, info, func(opts tfgen.GeneratorOptions) error {
 
 		if info.MetadataInfo == nil {
 			return fmt.Errorf("ProviderInfo.MetadataInfo is required and cannot be nil")


Test patch:
diff --git a/pf/tests/internal/testprovider/cmd/pulumi-resource-muxedrandom/main.go b/pf/tests/internal/testprovider/cmd/pulumi-resource-muxedrandom/main.go
index b1ef8767..e1fda80e 100644
--- a/pf/tests/internal/testprovider/cmd/pulumi-resource-muxedrandom/main.go
+++ b/pf/tests/internal/testprovider/cmd/pulumi-resource-muxedrandom/main.go
@@ -27,6 +27,6 @@ import (
 var schema []byte
 
 func main() {
-	tfbridge.MainWithMuxer(context.Background(), schema,
-		testprovider.MuxedRandomProvider())
+	tfbridge.MainWithMuxer(context.Background(), "muxedrandom",
+		testprovider.MuxedRandomProvider(), schema)
 }
diff --git a/pf/tests/internal/testprovider/cmd/pulumi-tfgen-muxedrandom/main.go b/pf/tests/internal/testprovider/cmd/pulumi-tfgen-muxedrandom/main.go
index 24575c6a..492372f7 100644
--- a/pf/tests/internal/testprovider/cmd/pulumi-tfgen-muxedrandom/main.go
+++ b/pf/tests/internal/testprovider/cmd/pulumi-tfgen-muxedrandom/main.go
@@ -22,5 +22,5 @@ import (
 )
 
 func main() {
-	tfgen.MainWithMuxer(testprovider.MuxedRandomProvider())
+	tfgen.MainWithMuxer("muxedrandom", testprovider.MuxedRandomProvider())
 }
diff --git a/pf/tests/provider_get_mapping_test.go b/pf/tests/provider_get_mapping_test.go
index 19b9e510..2442e15f 100644
--- a/pf/tests/provider_get_mapping_test.go
+++ b/pf/tests/provider_get_mapping_test.go
@@ -64,7 +64,7 @@ func TestMuxedGetMapping(t *testing.T) {
 
 	info := testprovider.MuxedRandomProvider()
 
-	server, err := tfbridge.MakeMuxedServer(ctx, genSDKSchema(t, info), info)(nil)
+	server, err := tfbridge.MakeMuxedServer(ctx, "muxedrandom", info, genSDKSchema(t, info))(nil)
 	require.NoError(t, err)
 
 	req := func(key string) (context.Context, *pulumirpc.GetMappingRequest) {
diff --git a/pf/tests/util.go b/pf/tests/util.go
index 28164bdb..4259ec65 100644
--- a/pf/tests/util.go
+++ b/pf/tests/util.go
@@ -38,7 +38,7 @@ func newProviderServer(t *testing.T, info tfbridge.ProviderInfo) pulumirpc.Resou
 func newMuxedProviderServer(t *testing.T, info tfbridge0.ProviderInfo) pulumirpc.ResourceProviderServer {
 	ctx := context.Background()
 	meta := genSDKSchema(t, info)
-	p, err := tfbridge.MakeMuxedServer(ctx, meta, info)(nil)
+	p, err := tfbridge.MakeMuxedServer(ctx, info.Name, info, meta)(nil)
 	require.NoError(t, err)
 	return p
 }