Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Latest commit

 

History

History
95 lines (66 loc) · 4.44 KB

translating-protocol-version-5-to-6.mdx

File metadata and controls

95 lines (66 loc) · 4.44 KB
page_title description
Plugin Development - Translating Protocol Version 5 to 6
Use the tf5to6server package in terraform-plugin-mux to translate protocol version 5 providers to protocol version 6.

Translating Protocol Version 5 to 6

The tf5to6server package enables translating a protocol version 5 provider server into a protocol version 6 provider server.

Use this package to:

Compatibility

Protocol version 6 provider servers are compatible with Terraform CLI 1.0 and later. Terraform CLI 1.1.5 and later is required to upgrade terraform-plugin-sdk/v2.

The following provider server implementations are supported:

Requirements

Upgrading provider servers from protocol version 5 to protocol version 6 has no provider code requirements.

If publishing to the Terraform Registry, set metadata.protocol_versions to ["6.0"] in the Terraform Registry manifest file.

Code Implementation

Use the tf5to6server.UpgradeServer() function to wrap a provider server. For most providers, this is either in the provider main() function of the root directory main.go file or where tf6muxserver is implemented in the codebase.

The following example upgrades a terraform-plugin-sdk/v2 provider.

upgradedSdkProvider, err := tf5to6server.UpgradeServer(
	context.Background(),
	sdkprovider.New(version)().GRPCProvider,
)

The following example uses tf6server to serve the upgraded provider directly.

err = tf6server.Serve(
	"registry.terraform.io/example/example",
	upgradedSdkProvider.ProviderServer,
)

The following example uses tf6muxserver to serve the upgraded provider while it is combined with others.

providers := []func() tfprotov6.ProviderServer{
	upgradedSdkProvider.ProviderServer,

	// Example terraform-plugin-framework provider
	providerserver.NewProtocol6(frameworkprovider.New(version)())
}

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

Refer to the tf6muxserver documentation for more details about how to serve the combined provider.

Testing Implementation

You can test the original provider using the same acceptance tests as before. Set the ProtoV6ProviderFactories field of TestCase to use the acceptance testing framework available in terraform-provider-sdk/v2/helper/resource.

The following example creates a test for a combined provider.

resource.Test(t, resource.TestCase{
	// ... other TestCase fields ...
	ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error) {
		"example": func() (tfprotov6.ProviderServer, error) {
			ctx := context.Background()
			upgradedSdkProvider, err := tf5to6server.UpgradeServer(
				ctx,
				sdkprovider.New("test")().GRPCProvider,
			)

			if err != nil {
				return nil, err
			}

			return upgradedSdkProvider.ProviderServer(), nil
		},
	},
})

Refer to the acceptance tests documentation for more details.