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

tf5muxserver/tf6muxserver: ValidateProviderConfig PrepareConfig Always Present With terraform-plugin-framework and terraform-plugin-sdk/v2 #51

Closed
bflad opened this issue Feb 8, 2022 · 2 comments · Fixed by #54
Assignees
Labels
bug Something isn't working
Milestone

Comments

@bflad
Copy link
Contributor

bflad commented Feb 8, 2022

terraform-plugin-mux version

v0.5.0

Relevant provider source code

// testAccProtoV6ProviderFactories are used to instantiate a provider during
// acceptance testing. The factory function will be invoked for every Terraform
// CLI command executed to create a provider server to which the CLI can
// reattach.
var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
	"topquark": func() (tfprotov6.ProviderServer, error) {
		ctx := context.Background()
		providers := []func() tfprotov6.ProviderServer{
			func() tfprotov6.ProviderServer {
				return tfsdk.NewProtocol6Server(provider1.New("test")())
			},
			func() tfprotov6.ProviderServer {
				return tfsdk.NewProtocol6Server(provider2.New("test")())
			},
		}

		muxServer, err := tf6muxserver.NewMuxServer(ctx, providers...)

		if err != nil {
			return nil, err
		}

		return muxServer, nil
	},
}

func TestAccExampleDataSource(t *testing.T) {
	resource.Test(t, resource.TestCase{
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Read testing
			{
				Config: testAccExampleDataSourceConfig,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("data.topquark_example1.test", "id", "example-id"),
					resource.TestCheckResourceAttr("data.topquark_example2.test", "id", "example-id"),
				),
			},
		},
	})
}

const testAccExampleDataSourceConfig = `
data "topquark_example1" "test" {
  configurable_attribute = "example"
}

data "topquark_example2" "test" {
  configurable_attribute = "example"
}
`

Expected Behavior

$ TF_ACC=1 go test ./...
...
ok	github.com/bflad/terraform-provider-topquark/internal/muxprovider

Actual Behavior

$ TF_ACC=1 go test ./...
...
--- FAIL: TestAccExampleDataSource (0.52s)
    muxprovider_test.go:43: Step 1/1 error: Error running pre-apply refresh: exit status 1

        Error: Plugin error

        The plugin returned an unexpected error from
        plugin6.(*GRPCProvider).ValidateProviderConfig: rpc error: code = Unknown
        desc = got a ValidateProviderConfig PreparedConfig response from multiple
        servers, not sure which to use

        Error: Invalid provider configuration

        Provider "registry.terraform.io/hashicorp/topquark" requires explicit
        configuration. Add a provider block to the root module and configure the
        provider's required arguments as described in the provider documentation.

terraform-plugin-framework@v0.5.0 always copies the ValidateProviderConfig.Request.Config into ValidateProviderConfig.Response.PreparedConfig, while tf6muxserver only allows up to one response (and cannot perform equality checking).

Steps to Reproduce

  • Use terraform apply with muxed terraform-plugin-framework + terraform-plugin-framework
  • Alternatively, run acceptance testing (TF_ACC=1 go test ./...) with muxed terraform-plugin-framework + terraform-plugin-framework

References

@bflad bflad added the bug Something isn't working label Feb 8, 2022
@bflad bflad changed the title tf6muxserver: ValidateProviderConfig PrepareConfig Always Present With terraform-plugin-framework tf5muxserver/tf6muxserver: ValidateProviderConfig PrepareConfig Always Present With terraform-plugin-framework and terraform-plugin-sdk/v2 Feb 8, 2022
@bflad
Copy link
Contributor Author

bflad commented Feb 8, 2022

This problem also applies to tf5muxserver and terraform-plugin-sdk/v2 providers, apparently.

https://github.com/hashicorp/terraform-plugin-sdk/blob/36ee3aa4bc4b9a4fa75ccf85b481293fa51c1ecc/helper/schema/grpc_provider.go#L226

--- FAIL: TestAccExampleDataSource (0.92s)
    muxprovider_test.go:39: Step 1/1 error: Error running pre-apply refresh: exit status 1

        Error: Invalid provider configuration

        Provider "registry.terraform.io/hashicorp/bottomquark" requires explicit
        configuration. Add a provider block to the root module and configure the
        provider's required arguments as described in the provider documentation.


        Error: Plugin error

          with provider["registry.terraform.io/hashicorp/bottomquark"],
          on <empty> line 0:
          (source code not available)

        The plugin returned an unexpected error from
        plugin.(*GRPCProvider).ValidateProviderConfig: rpc error: code = Unknown desc
        = got a PrepareProviderConfig PreparedConfig response from multiple servers,
        not sure which to use

@bflad bflad added this to the v0.5.1 milestone Feb 14, 2022
bflad added a commit to hashicorp/terraform-provider-corner that referenced this issue Feb 15, 2022
Reference: #42
Reference: hashicorp/terraform-plugin-mux#50
Reference: hashicorp/terraform-plugin-mux#51

This adds integration testing providers for the following terraform-plugin-mux packages:

- tf5muxserver
- tf5to6server
- tf6muxserver
- tf6to5server

The underlying providers are mainly decoupled duplicates of the existing frameworkprovider and sdkv2provider to prevent unintended changes across all the tests.

The `tf5muxserver` and `tf6muxserver` testing currently highlights the issue reported in hashicorp/terraform-plugin-mux#51:

```
--- FAIL: TestAccResourceUser (0.42s)
    provider_test.go:11: Step 1/1 error: Error running pre-apply refresh: exit status 1

        Error: Invalid provider configuration

        Provider "registry.terraform.io/hashicorp/tf5muxprovider" requires explicit
        configuration. Add a provider block to the root module and configure the
        provider's required arguments as described in the provider documentation.

        Error: Plugin error

          with provider["registry.terraform.io/hashicorp/tf5muxprovider"],
          on <empty> line 0:
          (source code not available)

        The plugin returned an unexpected error from
        plugin.(*GRPCProvider).ValidateProviderConfig: rpc error: code = Unknown desc
        = got a PrepareProviderConfig PreparedConfig response from multiple servers,
        not sure which to use
FAIL
FAIL    github.com/hashicorp/terraform-provider-corner/internal/tf5muxprovider  0.859s

--- FAIL: TestAccResourceUser (0.51s)
    provider_test.go:11: Step 1/1 error: Error running pre-apply refresh: exit status 1

        Error: Plugin error

        The plugin returned an unexpected error from
        plugin6.(*GRPCProvider).ValidateProviderConfig: rpc error: code = Unknown
        desc = got a ValidateProviderConfig PreparedConfig response from multiple
        servers, not sure which to use

        Error: Invalid provider configuration

        Provider "registry.terraform.io/hashicorp/tf6muxprovider" requires explicit
        configuration. Add a provider block to the root module and configure the
        provider's required arguments as described in the provider documentation.

FAIL
FAIL    github.com/hashicorp/terraform-provider-corner/internal/tf6muxprovider  2.914s
```

Which will require upstream updates in terraform-plugin-mux before it will pass.

Dependencies updated via:

```shell
# required for latest terraform-plugin-go usage until v0.6.0 is released
go get github.com/hashicorp/terraform-plugin-framework@main
go get github.com/hashicorp/terraform-plugin-mux@v0.5.0
```
@bflad bflad self-assigned this Feb 15, 2022
bflad added a commit that referenced this issue Feb 15, 2022
…g and ValidateProviderConfig

Reference: #51

Previously in real world usage:

```

    provider_test.go:11: Step 1/1 error: Error running pre-apply refresh: exit status 1

        Error: Invalid provider configuration

        Provider "registry.terraform.io/hashicorp/tf5muxprovider" requires explicit
        configuration. Add a provider block to the root module and configure the
        provider's required arguments as described in the provider documentation.

        Error: Plugin error

          with provider["registry.terraform.io/hashicorp/tf5muxprovider"],
          on <empty> line 0:
          (source code not available)

        The plugin returned an unexpected error from
        plugin.(*GRPCProvider).ValidateProviderConfig: rpc error: code = Unknown desc
        = got a PrepareProviderConfig PreparedConfig response from multiple servers,
        not sure which to use

    provider_test.go:11: Step 1/1 error: Error running pre-apply refresh: exit status 1

        Error: Plugin error

        The plugin returned an unexpected error from
        plugin6.(*GRPCProvider).ValidateProviderConfig: rpc error: code = Unknown
        desc = got a ValidateProviderConfig PreparedConfig response from multiple
        servers, not sure which to use

        Error: Invalid provider configuration

        Provider "registry.terraform.io/hashicorp/tf6muxprovider" requires explicit
        configuration. Add a provider block to the root module and configure the
        provider's required arguments as described in the provider documentation.
```

Updated unit testing before code changes:

```
--- FAIL: TestMuxServerPrepareProviderConfig (0.00s)
    --- FAIL: TestMuxServerPrepareProviderConfig/PreparedConfig-multiple-equal (0.00s)
        mux_server_PrepareProviderConfig_test.go:365: wanted no error, got error: got a PrepareProviderConfig PreparedConfig response from multiple servers, not sure which to use
FAIL
FAIL    github.com/hashicorp/terraform-plugin-mux/tf5muxserver  1.244s

--- FAIL: TestMuxServerValidateProviderConfig (0.00s)
    --- FAIL: TestMuxServerValidateProviderConfig/PreparedConfig-multiple-equal (0.00s)
        mux_server_ValidateProviderConfig_test.go:365: wanted no error, got error: got a ValidateProviderConfig PreparedConfig response from multiple servers, not sure which to use
FAIL
FAIL    github.com/hashicorp/terraform-plugin-mux/tf6muxserver  0.665s
```

Verified those integration tests are now passing by replacing the mux dependency with this branch. Once those tests are published, we can introduce the integration tests into this project's testing workflow.
@bflad bflad closed this as completed in #54 Feb 17, 2022
bflad added a commit that referenced this issue Feb 17, 2022
…g and ValidateProviderConfig (#54)

Reference: #51

Previously in real world usage:

```

    provider_test.go:11: Step 1/1 error: Error running pre-apply refresh: exit status 1

        Error: Invalid provider configuration

        Provider "registry.terraform.io/hashicorp/tf5muxprovider" requires explicit
        configuration. Add a provider block to the root module and configure the
        provider's required arguments as described in the provider documentation.

        Error: Plugin error

          with provider["registry.terraform.io/hashicorp/tf5muxprovider"],
          on <empty> line 0:
          (source code not available)

        The plugin returned an unexpected error from
        plugin.(*GRPCProvider).ValidateProviderConfig: rpc error: code = Unknown desc
        = got a PrepareProviderConfig PreparedConfig response from multiple servers,
        not sure which to use

    provider_test.go:11: Step 1/1 error: Error running pre-apply refresh: exit status 1

        Error: Plugin error

        The plugin returned an unexpected error from
        plugin6.(*GRPCProvider).ValidateProviderConfig: rpc error: code = Unknown
        desc = got a ValidateProviderConfig PreparedConfig response from multiple
        servers, not sure which to use

        Error: Invalid provider configuration

        Provider "registry.terraform.io/hashicorp/tf6muxprovider" requires explicit
        configuration. Add a provider block to the root module and configure the
        provider's required arguments as described in the provider documentation.
```

Updated unit testing before code changes:

```
--- FAIL: TestMuxServerPrepareProviderConfig (0.00s)
    --- FAIL: TestMuxServerPrepareProviderConfig/PreparedConfig-multiple-equal (0.00s)
        mux_server_PrepareProviderConfig_test.go:365: wanted no error, got error: got a PrepareProviderConfig PreparedConfig response from multiple servers, not sure which to use
FAIL
FAIL    github.com/hashicorp/terraform-plugin-mux/tf5muxserver  1.244s

--- FAIL: TestMuxServerValidateProviderConfig (0.00s)
    --- FAIL: TestMuxServerValidateProviderConfig/PreparedConfig-multiple-equal (0.00s)
        mux_server_ValidateProviderConfig_test.go:365: wanted no error, got error: got a ValidateProviderConfig PreparedConfig response from multiple servers, not sure which to use
FAIL
FAIL    github.com/hashicorp/terraform-plugin-mux/tf6muxserver  0.665s
```

Verified those integration tests are now passing by replacing the mux dependency with this branch. Once those tests are published, we can introduce the integration tests into this project's testing workflow.
bflad added a commit to hashicorp/terraform-provider-corner that referenced this issue Feb 22, 2022
Reference: #42
Reference: hashicorp/terraform-plugin-mux#50
Reference: hashicorp/terraform-plugin-mux#51

This adds integration testing providers for the following terraform-plugin-mux packages:

- tf5muxserver
- tf5to6server
- tf6muxserver
- tf6to5server

The underlying providers are mainly decoupled duplicates of the existing frameworkprovider and sdkv2provider to prevent unintended changes across all the tests.
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 24, 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