Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: vendor more OpenTOFU code #2718

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions dynamic/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
LDFLAGS := -ldflags "-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=ignore"

build: bin
go build \
-o bin/pulumi-resource-terraform-provider \
${LDFLAGS} \
github.com/pulumi/pulumi-terraform-bridge/dynamic

install: build
Expand All @@ -12,15 +9,15 @@ install: build
--file bin/pulumi-resource-terraform-provider --reinstall

test_unit:
cd internal/shim && go test ${LDFLAGS} ./...
go test -short ${LDFLAGS} ./...
cd internal/shim && go test ./...
go test -short ./...

test:
cd internal/shim && go test -v ${LDFLAGS} ./...
go test -v ${LDFLAGS} ./...
cd internal/shim && go test -v ./...
go test -v ./...

test_accept:
go test -v ${LDFLAGS} ./... -update
go test -v ./... -update

bin:
mkdir bin
Expand Down
30 changes: 16 additions & 14 deletions dynamic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ Diving deeper into how the repository is laid out, we see:
├── info.go
├── internal/
│ └── shim/
│ ├── go.mod
│ ├── go.sum
│ ├── protov5/
│ │ ├── provider.go
│ │ └── translate/
Expand All @@ -120,8 +118,8 @@ Diving deeper into how the repository is laid out, we see:
└── version.go
```

The dynamic provider layer consists by design of small, specialized packages.
As of time of writing, the entire `dynamic` folder is only 2288 lines of go code[^1].
The dynamic provider layer consists by design of small, specialized packages.
As of time of writing, the entire `dynamic` folder is only 2288 lines of go code[^1].
Let's go through each package in turn.

[^1]: `loc --exclude '*._test.go'`
Expand Down Expand Up @@ -172,17 +170,21 @@ type Provider interface {

- `run.LocalProvider` takes a path to a Terraform provider and runs it.

When `run` launches a Terraform provider, the provider may implement either the
[`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
[`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):
When `run` launches a Terraform provider, the provider may implement either the `tfplugin5.ProviderClient` or
`tfplugin6.ProviderClient` interface. `run` must return a
[`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):

``` go
func tf5to6server.UpgradeServer(context.Context, func() tfprotov5.ProviderServer) (tfprotov6.ProviderServer, error)
```

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)
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
section.
We still need to be able to translate from `tfplugin5.ProviderClient` and `tfplugin6.ProviderClient` 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 section.

### `package protov5` & `package protov6`

Expand All @@ -203,8 +205,8 @@ A representative gRPC handler looks like this:
``` go
// tfprotov6/provider.go
import (
"github.com/opentofu/opentofu/internal/tfplugin6"
"github.com/opentofu/opentofu/shim/protov6/translate"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/vendored/tfplugin6"
"github.com/pulumi/pulumi-terraform-bridge/dynamic/internal/shim/protov6/translate"
)

...
Expand All @@ -225,7 +227,7 @@ The `translate.ReadResourceRequest` call looks like this:
// tfprotov6/translate/tfplugin6.go
import (
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/opentofu/opentofu/internal/tfplugin6"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/vendored/tfplugin6"
)

...
Expand Down Expand Up @@ -283,4 +285,4 @@ Dynamically bridged providers allow the Terraform provider interactions to be re
1. To reproduce the behaviour, maintainers should use the `tf-logs.json` like in `dynamic/log_replay_provider.go:TestLogReplayProviderWithProgram`:
1. Dump the sanitized log file under `testadata`.
1. Use `NewLogReplayProvider` to create a provider which will replay the calls encountered by the user.
2. Use the `pulcheck` utility to mimic the user actions which triggered the behaviour, like `Preview` and `Up`
2. Use the `pulcheck` utility to mimic the user actions which triggered the behaviour, like `Preview` and `Up`
54 changes: 8 additions & 46 deletions dynamic/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ replace (
// Use Pulumi's fork of the terraform-plugin-sdk.
github.com/hashicorp/terraform-plugin-sdk/v2 => github.com/pulumi/terraform-plugin-sdk/v2 v2.0.0-20240520223432-0c0bf0d65f10

github.com/opentofu/opentofu/shim => ./internal/shim
github.com/pulumi/pulumi-terraform-bridge/v3 => ../
)

require (
github.com/blang/semver v3.5.1+incompatible
github.com/hashicorp/terraform-plugin-sdk v1.7.0
github.com/hexops/autogold/v2 v2.2.1
github.com/opentofu/opentofu/shim v0.0.0-00010101000000-000000000000
github.com/pulumi/providertest v0.1.3
github.com/pulumi/pulumi-terraform-bridge/v3 v3.92.0
github.com/stretchr/testify v1.9.0
Expand All @@ -43,7 +41,6 @@ require (
cloud.google.com/go v0.112.1 // indirect
cloud.google.com/go/compute/metadata v0.5.0 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/kms v1.15.7 // indirect
cloud.google.com/go/storage v1.39.1 // indirect
dario.cat/mergo v1.0.0 // indirect
github.com/BurntSushi/toml v1.2.1 // indirect
Expand All @@ -57,38 +54,13 @@ require (
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/apparentlymart/go-versions v1.0.1 // indirect
github.com/apparentlymart/go-versions v1.0.3
github.com/armon/go-radix v1.0.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aws/aws-sdk-go v1.50.36 // indirect
github.com/aws/aws-sdk-go-v2 v1.26.1 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.11 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.11 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.5 // indirect
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.25.5 // indirect
github.com/aws/aws-sdk-go-v2/service/iam v1.31.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.7 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.8.5 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5 // indirect
github.com/aws/aws-sdk-go-v2/service/kms v1.30.1 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sqs v1.31.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 // indirect
github.com/aws/smithy-go v1.20.2 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/bmatcuk/doublestar/v4 v4.6.0 // indirect
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
github.com/charmbracelet/bubbles v0.16.1 // indirect
github.com/charmbracelet/bubbletea v0.25.0 // indirect
github.com/charmbracelet/lipgloss v0.7.1 // indirect
Expand All @@ -107,7 +79,6 @@ require (
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.12.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
Expand All @@ -121,31 +92,26 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.2 // indirect
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.43 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
github.com/hashicorp/go-getter v1.7.5 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.6.1 // indirect
github.com/hashicorp/go-plugin v1.6.1
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8 // indirect
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.6 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/hcl/v2 v2.22.0 // indirect
github.com/hashicorp/hil v0.0.0-20190212132231-97b3a9cdfa93 // indirect
github.com/hashicorp/terraform-plugin-framework v1.12.0 // indirect
github.com/hashicorp/terraform-plugin-framework v1.12.0
github.com/hashicorp/terraform-plugin-go v0.24.0
github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect
github.com/hashicorp/terraform-plugin-mux v0.16.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-mux v0.16.0
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/terraform-svchost v0.1.1
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/hexops/valast v1.4.4 // indirect
Expand Down Expand Up @@ -181,9 +147,7 @@ require (
github.com/natefinch/atomic v1.0.1 // indirect
github.com/nightlyone/lockfile v1.0.0 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/openbao/openbao/api v0.0.0-20240326035453-c075f0ef2c7e // indirect
github.com/opentofu/opentofu v1.7.1 // indirect
github.com/opentofu/registry-address v0.0.0-20230922120653-901b9ae4061a // indirect
github.com/opentofu/registry-address v0.0.0-20230922120653-901b9ae4061a
github.com/opentracing/basictracer-go v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pgavlin/fx v0.1.6 // indirect
Expand All @@ -204,7 +168,6 @@ require (
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 // indirect
github.com/segmentio/asm v1.1.3 // indirect
Expand All @@ -226,7 +189,6 @@ require (
github.com/zclconf/go-cty v1.14.4 // indirect
github.com/zclconf/go-cty-yaml v1.0.3 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.46.1 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
Expand All @@ -248,7 +210,7 @@ require (
google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/grpc v1.67.1
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/frand v1.4.2 // indirect
Expand Down
Loading
Loading