@@ -17,6 +17,7 @@ package tfbridge
1717import (
1818 "context"
1919 "fmt"
20+ "os"
2021
2122 "github.com/blang/semver"
2223 pfprovider "github.com/hashicorp/terraform-plugin-framework/provider"
@@ -27,6 +28,7 @@ import (
2728 "github.com/pulumi/pulumi/sdk/v3/go/common/resource"
2829 "github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
2930 "github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
31+ "github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"
3032 "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
3133 "github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
3234 pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go"
@@ -42,6 +44,31 @@ import (
4244 "github.com/pulumi/pulumi-terraform-bridge/v3/unstable/logging"
4345)
4446
47+ type providerOptions struct {
48+ enableAccurateBridgePreview bool
49+ }
50+
51+ type providerOption func (providerOptions ) (providerOptions , error )
52+
53+ func withAccurateBridgePreview () providerOption {
54+ return func (opts providerOptions ) (providerOptions , error ) {
55+ opts .enableAccurateBridgePreview = true
56+ return opts , nil
57+ }
58+ }
59+
60+ func getProviderOptions (opts []providerOption ) (providerOptions , error ) {
61+ res := providerOptions {}
62+ for _ , o := range opts {
63+ var err error
64+ res , err = o (res )
65+ if err != nil {
66+ return res , err
67+ }
68+ }
69+ return res , nil
70+ }
71+
4572// Provider implements the Pulumi resource provider operations for any
4673// Terraform plugin built with Terraform Plugin Framework.
4774//
@@ -66,6 +93,7 @@ type provider struct {
6693 lastKnownProviderConfig resource.PropertyMap
6794
6895 schemaOnlyProvider shim.Provider
96+ providerOpts []providerOption
6997}
7098
7199var _ pl.ProviderWithContext = & provider {}
@@ -148,6 +176,11 @@ func newProviderWithContext(ctx context.Context, info tfbridge.ProviderInfo,
148176 }
149177 }
150178
179+ opts := []providerOption {}
180+ if info .EnableAccurateBridgePreview || cmdutil .IsTruthy (os .Getenv ("PULUMI_TF_BRIDGE_ACCURATE_BRIDGE_PREVIEW" )) {
181+ opts = append (opts , withAccurateBridgePreview ())
182+ }
183+
151184 p := & provider {
152185 tfServer : server6 ,
153186 info : info ,
@@ -160,6 +193,7 @@ func newProviderWithContext(ctx context.Context, info tfbridge.ProviderInfo,
160193 version : semverVersion ,
161194 schemaOnlyProvider : info .P ,
162195 parameterize : meta .XParamaterize ,
196+ providerOpts : opts ,
163197 }
164198
165199 return configencoding .New (p ), nil
0 commit comments