You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Document the architecture for dynamic providers (#2137)
Fixespulumi/home#3471
As part of documenting what each package does, I moved `loader*.go` from
`shim` to `shim/run`, which I think reads clearer. There are no runtime
changes in this commit.
---------
Co-authored-by: VenelinMartinov <[email protected]>
The dynamic provider layer is by-design as simple and straight-forward as possible. Each package does one
131
+
thing only and there isn't that much code. As of time of writing, the entire `dynamic` folder is only 2288
132
+
lines of go code[^1]. I'll go through each package in turn.
133
+
134
+
[^1]: `loc --exclude '*._test.go'`
135
+
136
+
### `package main`
137
+
138
+
`package main` is responsible for launching a Pulumi provider and setting up the parameterize call. It does
139
+
this by calling [`pf/tfbridge.Main`](https://pkg.go.dev/github.com/pulumi/pulumi-terraform-bridge/[email protected]/tfbridge#Main), passing in an empty PF provider (from
140
+
[`pf/proto.Empty()`](https://pkg.go.dev/github.com/pulumi/pulumi-terraform-bridge/[email protected]/proto#Empty)). [`pf/tfbridge.ProviderMetadata`](https://pkg.go.dev/github.com/pulumi/pulumi-terraform-bridge/[email protected]/tfbridge#ProviderMetadata) allows overriding the `Parameterize` and
141
+
`GetSchema` call (and we override both).
142
+
143
+
When `Parameterize` is called, we launch the underlying Terraform provider via
144
+
`internal/shim/run.LocalProvider` or `internal/shim/run.NamedProvider` (downloading as necessary). Both
145
+
functions return a [`tfprotov6.ProviderServer`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-go/tfprotov6#ProviderServer) which is used to re-initialize the running provider via
When `GetSchema` is called, it generates a schema from the currently equipped provider with
149
+
[`pkg/tfgen.GenerateSchemaWithOptions`](https://pkg.go.dev/github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen#GenerateSchemaWithOptions) and returns is. All type translation, documentation generation, etc
150
+
are done with standard bridge based functionality.
151
+
152
+
All other gRPC calls (`Create`, `Read`, `Update`, `Delete`, etc.) are handled normally by `pf`'s existing
153
+
server.
154
+
155
+
### `package version`
156
+
157
+
`version.version` is used as a link-time target to bake in the release version to the provider binary. This is
158
+
the same mechanism that Pulumi uses to embed versions in all of our binaries.
159
+
160
+
### `package run`
161
+
162
+
`run` defines a running provider for the purposes of `dynamic`.
163
+
164
+
```go
165
+
typeProviderinterface {
166
+
tfprotov6.ProviderServer
167
+
io.Closer
168
+
169
+
Name() string
170
+
Version() string
171
+
}
172
+
```
173
+
174
+
`run` also defines functions to "run" the underlying TF provider:
175
+
176
+
-`run.NamedProvider` takes a provider definition like `("cloudfront/cloudfront", ">= 3.2.0")` and loads the
177
+
provider (downloading it if necessary). Named Terraform providers are cached in
178
+
`PULUMI_DYNAMIC_TF_PLUGIN_CACHE_DIR` (defaulting to `$PULUMI_HOME/dynamic_tf_plugins`).
179
+
180
+
-`run.LocalProvider` takes a path to a Terraform provider and runs it.
181
+
182
+
When `run` launches a Terraform provider, the provider may implement either the
183
+
[`tfplugin5.ProviderClient`](https://pkg.go.dev/github.com/opentofu/opentofu/internal/tfplugin5#ProviderClient) or [`tfplugin6.ProviderClient`](https://pkg.go.dev/github.com/opentofu/opentofu/internal/tfplugin6#ProviderClient) interface. `run` must return a
184
+
[`tfprotov6.ProviderServer`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-go/tfprotov6#ProviderServer). The Terraform ecosystem helps with [translating from v5 to v6](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-mux/tf5to6server#UpgradeServer):
We still need to be able to translate from [`tfplugin5.ProviderClient`](https://pkg.go.dev/github.com/opentofu/opentofu/internal/tfplugin5#ProviderClient) and [`tfplugin6.ProviderClient`](https://pkg.go.dev/github.com/opentofu/opentofu/internal/tfplugin6#ProviderClient)
191
+
to [`tfprotov5.ProviderServer`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-go/tfprotov5#ProviderServer) and [`tfprotov6.ProviderServer`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-go/tfprotov6#ProviderServer) respectively. For that, see the next
192
+
section.
193
+
194
+
### `package protov5` & `package protov6`
195
+
196
+
`package protov5` and `package protov6` are nearly identical packages that translate between gRPC level client
197
+
types to just above gRPC level server types. Both packages are identical in structure, exposing one end point:
0 commit comments