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

Using tf5server with terraform-plugin-sdk/helper/resource Does Not Use Log Sink #152

Closed
bflad opened this issue Feb 4, 2022 · 1 comment · Fixed by #153
Closed

Using tf5server with terraform-plugin-sdk/helper/resource Does Not Use Log Sink #152

bflad opened this issue Feb 4, 2022 · 1 comment · Fixed by #153
Labels
bug Something isn't working
Milestone

Comments

@bflad
Copy link
Contributor

bflad commented Feb 4, 2022

terraform-plugin-go version

v0.7.0

Relevant provider source code

Reference: https://github.com/hashicorp/terraform-provider-corner/tree/main/internal/sdkv2provider
Reference: tf5server implementation via hashicorp/terraform-plugin-sdk#857

Terraform Configuration Files

Any will do.

Expected Behavior

TF_ACC=1 go test -timeout=1m -v ./internal/sdkv2provider
=== RUN   TestProvider
--- PASS: TestProvider (0.00s)
=== RUN   TestProvider_impl
--- PASS: TestProvider_impl (0.00s)
=== RUN   TestAccTests
=== RUN   TestAccTests/corner_regions_cty
=== RUN   TestAccTests/corner_user
=== RUN   TestAccTests/corner_regions
=== RUN   TestAccTests/corner_bigint_data
=== RUN   TestAccTests/corner_bigint
=== RUN   TestAccTests/corner_user_cty
--- PASS: TestAccTests (6.76s)
    --- PASS: TestAccTests/corner_regions_cty (1.24s)
    --- PASS: TestAccTests/corner_user (1.02s)
    --- PASS: TestAccTests/corner_regions (0.92s)
    --- PASS: TestAccTests/corner_bigint_data (0.92s)
    --- PASS: TestAccTests/corner_bigint (0.97s)
    --- PASS: TestAccTests/corner_user_cty (1.69s)
PASS
ok      github.com/hashicorp/terraform-provider-corner/internal/sdkv2provider   7.510s

Actual Behavior

TF_ACC=1 go test -timeout=1m -v ./internal/sdkv2provider
=== RUN   TestProvider
--- PASS: TestProvider (0.00s)
=== RUN   TestProvider_impl
--- PASS: TestProvider_impl (0.00s)
=== RUN   TestAccTests
=== RUN   TestAccTests/corner_user
{"@caller":"/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.7.0/internal/logging/protocol.go:21","@level":"trace","@message":"Received request","@module":"sdk.proto","@timestamp":"2022-02-04T16:28:52.602080-05:00","EXTRA_VALUE_AT_END":null,"tf_proto_version":"5.2","tf_provider_addr":"","tf_req_id":"a24b8a29-628a-01c2-0516-08b260627109","tf_rpc":"GetProviderSchema"}
{"@caller":"/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.7.0/internal/logging/protocol.go:21","@level":"trace","@message":"Calling downstream","@module":"sdk.proto","@timestamp":"2022-02-04T16:28:52.602157-05:00","EXTRA_VALUE_AT_END":null,"tf_proto_version":"5.2","tf_provider_addr":"","tf_req_id":"a24b8a29-628a-01c2-0516-08b260627109","tf_rpc":"GetProviderSchema"}
{"@caller":"/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.7.0/internal/logging/protocol.go:21","@level":"trace","@message":"Called downstream","@module":"sdk.proto","@timestamp":"2022-02-04T16:28:52.602257-05:00","EXTRA_VALUE_AT_END":null,"tf_proto_version":"5.2","tf_provider_addr":"","tf_req_id":"a24b8a29-628a-01c2-0516-08b260627109","tf_rpc":"GetProviderSchema"}
{"@caller":"/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.7.0/internal/logging/protocol.go:21","@level":"trace","@message":"Served request","@module":"sdk.proto","@timestamp":"2022-02-04T16:28:52.602299-05:00","EXTRA_VALUE_AT_END":null,"tf_proto_version":"5.2","tf_provider_addr":"","tf_req_id":"a24b8a29-628a-01c2-0516-08b260627109","tf_rpc":"GetProviderSchema"}
{"@caller":"/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.7.0/internal/logging/protocol.go:21","@level":"trace","@message":"Received request","@module":"sdk.proto","@timestamp":"2022-02-04T16:28:52.666614-05:00","EXTRA_VALUE_AT_END":null,"tf_proto_version":"5.2","tf_provider_addr":"","tf_req_id":"97a74410-24d3-4d4e-c61c-9062200c75e8","tf_rpc":"GetProviderSchema"}
... many more ...

The ServeOpts are not being passed into the GRPCProviderPlugin.Opts in the Serve function, therefore options like our using our logging sink implementation cannot take affect.

Steps to Reproduce

In a terraform-plugin-sdk/v2 provider:

  1. go mod edit -replace=github.com/hashicorp/terraform-plugin-sdk/v2=/Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk@bflad-tpg-servers
  2. go mod tidy
  3. TF_ACC=1 go test -v ./...

References

@bflad bflad added the bug Something isn't working label Feb 4, 2022
@bflad bflad added this to the v0.8.0 milestone Feb 4, 2022
bflad added a commit that referenced this issue Feb 4, 2022
Reference: #152

Currently this functionality cannot implement unit testing without a larger refactoring effort as there is no way to retrieve the generated `ServeConfig` and `plugin.ServeConfig` inside the function. While refactoring that logic into an unexported function such as:

```go
func prepareServeConfigs(providerAddress string, providerServerFunc func() tfprotov5.ProviderServer, opts ...ServeOpt) (*ServeConfig, *plugin.ServeConfig, error)
```

Would be fairly straightforward, the `ServeConfig` itself implements all unexported fields which presents some tougher challenges with `go-cmp`:

```
	panic: cannot handle unexported field at {*tf5server.ServeConfig}.logger:
	"github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server".ServeConfig
consider using a custom Comparer; if you control the implementation of type, you can also consider using an Exporter, AllowUnexported, or cmpopts.IgnoreUnexported
```

This chooses instead to fix the implementation to match `tf6server`, rather than bundle all this unrelated work into the simple bug fix.

Previously:

```console
❯ TF_ACC=1 go test -timeout=1m -v ./internal/sdkv2provider
=== RUN   TestProvider
--- PASS: TestProvider (0.00s)
=== RUN   TestProvider_impl
--- PASS: TestProvider_impl (0.00s)
=== RUN   TestAccTests
=== RUN   TestAccTests/corner_user
{"@caller":"/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.7.0/internal/logging/protocol.go:21","@Level":"trace","@message":"Received request","@module":"sdk.proto","@timestamp":"2022-02-04T16:28:52.602080-05:00","EXTRA_VALUE_AT_END":null,"tf_proto_version":"5.2","tf_provider_addr":"","tf_req_id":"a24b8a29-628a-01c2-0516-08b260627109","tf_rpc":"GetProviderSchema"}
{"@caller":"/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.7.0/internal/logging/protocol.go:21","@Level":"trace","@message":"Calling downstream","@module":"sdk.proto","@timestamp":"2022-02-04T16:28:52.602157-05:00","EXTRA_VALUE_AT_END":null,"tf_proto_version":"5.2","tf_provider_addr":"","tf_req_id":"a24b8a29-628a-01c2-0516-08b260627109","tf_rpc":"GetProviderSchema"}
{"@caller":"/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.7.0/internal/logging/protocol.go:21","@Level":"trace","@message":"Called downstream","@module":"sdk.proto","@timestamp":"2022-02-04T16:28:52.602257-05:00","EXTRA_VALUE_AT_END":null,"tf_proto_version":"5.2","tf_provider_addr":"","tf_req_id":"a24b8a29-628a-01c2-0516-08b260627109","tf_rpc":"GetProviderSchema"}
{"@caller":"/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.7.0/internal/logging/protocol.go:21","@Level":"trace","@message":"Served request","@module":"sdk.proto","@timestamp":"2022-02-04T16:28:52.602299-05:00","EXTRA_VALUE_AT_END":null,"tf_proto_version":"5.2","tf_provider_addr":"","tf_req_id":"a24b8a29-628a-01c2-0516-08b260627109","tf_rpc":"GetProviderSchema"}
{"@caller":"/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.7.0/internal/logging/protocol.go:21","@Level":"trace","@message":"Received request","@module":"sdk.proto","@timestamp":"2022-02-04T16:28:52.666614-05:00","EXTRA_VALUE_AT_END":null,"tf_proto_version":"5.2","tf_provider_addr":"","tf_req_id":"97a74410-24d3-4d4e-c61c-9062200c75e8","tf_rpc":"GetProviderSchema"}
... many more ...
```

Now:

```console
❯ TF_ACC=1 go test -timeout=1m -v ./internal/sdkv2provider
=== RUN   TestProvider
--- PASS: TestProvider (0.00s)
=== RUN   TestProvider_impl
--- PASS: TestProvider_impl (0.00s)
=== RUN   TestAccTests
=== RUN   TestAccTests/corner_regions_cty
=== RUN   TestAccTests/corner_user
=== RUN   TestAccTests/corner_regions
=== RUN   TestAccTests/corner_bigint_data
=== RUN   TestAccTests/corner_bigint
=== RUN   TestAccTests/corner_user_cty
--- PASS: TestAccTests (6.76s)
    --- PASS: TestAccTests/corner_regions_cty (1.24s)
    --- PASS: TestAccTests/corner_user (1.02s)
    --- PASS: TestAccTests/corner_regions (0.92s)
    --- PASS: TestAccTests/corner_bigint_data (0.92s)
    --- PASS: TestAccTests/corner_bigint (0.97s)
    --- PASS: TestAccTests/corner_user_cty (1.69s)
PASS
ok      github.com/hashicorp/terraform-provider-corner/internal/sdkv2provider   7.510s
```
@bflad bflad closed this as completed in #153 Feb 7, 2022
bflad added a commit that referenced this issue Feb 7, 2022
…tup (#153)

Reference: #152

Currently this functionality cannot implement unit testing without a larger refactoring effort as there is no way to retrieve the generated `ServeConfig` and `plugin.ServeConfig` inside the function. While refactoring that logic into an unexported function such as:

```go
func prepareServeConfigs(providerAddress string, providerServerFunc func() tfprotov5.ProviderServer, opts ...ServeOpt) (*ServeConfig, *plugin.ServeConfig, error)
```

Would be fairly straightforward, the `ServeConfig` itself implements all unexported fields which presents some tougher challenges with `go-cmp`:

```
	panic: cannot handle unexported field at {*tf5server.ServeConfig}.logger:
	"github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server".ServeConfig
consider using a custom Comparer; if you control the implementation of type, you can also consider using an Exporter, AllowUnexported, or cmpopts.IgnoreUnexported
```

This chooses instead to fix the implementation to match `tf6server`, rather than bundle all this unrelated work into the simple bug fix.

Previously:

```console
❯ TF_ACC=1 go test -timeout=1m -v ./internal/sdkv2provider
=== RUN   TestProvider
--- PASS: TestProvider (0.00s)
=== RUN   TestProvider_impl
--- PASS: TestProvider_impl (0.00s)
=== RUN   TestAccTests
=== RUN   TestAccTests/corner_user
{"@caller":"/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.7.0/internal/logging/protocol.go:21","@Level":"trace","@message":"Received request","@module":"sdk.proto","@timestamp":"2022-02-04T16:28:52.602080-05:00","EXTRA_VALUE_AT_END":null,"tf_proto_version":"5.2","tf_provider_addr":"","tf_req_id":"a24b8a29-628a-01c2-0516-08b260627109","tf_rpc":"GetProviderSchema"}
{"@caller":"/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.7.0/internal/logging/protocol.go:21","@Level":"trace","@message":"Calling downstream","@module":"sdk.proto","@timestamp":"2022-02-04T16:28:52.602157-05:00","EXTRA_VALUE_AT_END":null,"tf_proto_version":"5.2","tf_provider_addr":"","tf_req_id":"a24b8a29-628a-01c2-0516-08b260627109","tf_rpc":"GetProviderSchema"}
{"@caller":"/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.7.0/internal/logging/protocol.go:21","@Level":"trace","@message":"Called downstream","@module":"sdk.proto","@timestamp":"2022-02-04T16:28:52.602257-05:00","EXTRA_VALUE_AT_END":null,"tf_proto_version":"5.2","tf_provider_addr":"","tf_req_id":"a24b8a29-628a-01c2-0516-08b260627109","tf_rpc":"GetProviderSchema"}
{"@caller":"/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.7.0/internal/logging/protocol.go:21","@Level":"trace","@message":"Served request","@module":"sdk.proto","@timestamp":"2022-02-04T16:28:52.602299-05:00","EXTRA_VALUE_AT_END":null,"tf_proto_version":"5.2","tf_provider_addr":"","tf_req_id":"a24b8a29-628a-01c2-0516-08b260627109","tf_rpc":"GetProviderSchema"}
{"@caller":"/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.7.0/internal/logging/protocol.go:21","@Level":"trace","@message":"Received request","@module":"sdk.proto","@timestamp":"2022-02-04T16:28:52.666614-05:00","EXTRA_VALUE_AT_END":null,"tf_proto_version":"5.2","tf_provider_addr":"","tf_req_id":"97a74410-24d3-4d4e-c61c-9062200c75e8","tf_rpc":"GetProviderSchema"}
... many more ...
```

Now:

```console
❯ TF_ACC=1 go test -timeout=1m -v ./internal/sdkv2provider
=== RUN   TestProvider
--- PASS: TestProvider (0.00s)
=== RUN   TestProvider_impl
--- PASS: TestProvider_impl (0.00s)
=== RUN   TestAccTests
=== RUN   TestAccTests/corner_regions_cty
=== RUN   TestAccTests/corner_user
=== RUN   TestAccTests/corner_regions
=== RUN   TestAccTests/corner_bigint_data
=== RUN   TestAccTests/corner_bigint
=== RUN   TestAccTests/corner_user_cty
--- PASS: TestAccTests (6.76s)
    --- PASS: TestAccTests/corner_regions_cty (1.24s)
    --- PASS: TestAccTests/corner_user (1.02s)
    --- PASS: TestAccTests/corner_regions (0.92s)
    --- PASS: TestAccTests/corner_bigint_data (0.92s)
    --- PASS: TestAccTests/corner_bigint (0.97s)
    --- PASS: TestAccTests/corner_user_cty (1.69s)
PASS
ok      github.com/hashicorp/terraform-provider-corner/internal/sdkv2provider   7.510s
```
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
1 participant