@@ -17,6 +17,7 @@ package tfbridge
17
17
import (
18
18
"context"
19
19
"fmt"
20
+ "os"
20
21
21
22
"github.com/blang/semver"
22
23
pfprovider "github.com/hashicorp/terraform-plugin-framework/provider"
@@ -27,6 +28,7 @@ import (
27
28
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
28
29
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
29
30
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
31
+ "github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"
30
32
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
31
33
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
32
34
pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go"
@@ -42,6 +44,31 @@ import (
42
44
"github.com/pulumi/pulumi-terraform-bridge/v3/unstable/logging"
43
45
)
44
46
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
+
45
72
// Provider implements the Pulumi resource provider operations for any
46
73
// Terraform plugin built with Terraform Plugin Framework.
47
74
//
@@ -66,6 +93,7 @@ type provider struct {
66
93
lastKnownProviderConfig resource.PropertyMap
67
94
68
95
schemaOnlyProvider shim.Provider
96
+ providerOpts []providerOption
69
97
}
70
98
71
99
var _ pl.ProviderWithContext = & provider {}
@@ -148,6 +176,11 @@ func newProviderWithContext(ctx context.Context, info tfbridge.ProviderInfo,
148
176
}
149
177
}
150
178
179
+ opts := []providerOption {}
180
+ if info .EnableAccurateBridgePreview || cmdutil .IsTruthy (os .Getenv ("PULUMI_TF_BRIDGE_ACCURATE_BRIDGE_PREVIEW" )) {
181
+ opts = append (opts , withAccurateBridgePreview ())
182
+ }
183
+
151
184
p := & provider {
152
185
tfServer : server6 ,
153
186
info : info ,
@@ -160,6 +193,7 @@ func newProviderWithContext(ctx context.Context, info tfbridge.ProviderInfo,
160
193
version : semverVersion ,
161
194
schemaOnlyProvider : info .P ,
162
195
parameterize : meta .XParamaterize ,
196
+ providerOpts : opts ,
163
197
}
164
198
165
199
return configencoding .New (p ), nil
0 commit comments