• HashiCorp Developer

  • HashiCorp Cloud Platform
  • Terraform
  • Packer
  • Consul
  • Vault
  • Boundary
  • Nomad
  • Waypoint
  • Vagrant
Terraform
  • Install
  • Tutorials
    • About the Docs
    • Configuration Language
    • Terraform CLI
    • Terraform Cloud
    • Terraform Enterprise
    • CDK for Terraform
    • Provider Use
    • Plugin Development
    • Registry Publishing
    • Integration Program
  • Registry(opens in new tab)
  • Try Cloud(opens in new tab)
  • Sign up
Plugin Development

Combining and Translating

Skip to main content
  • Combining and Translating
  • Combining Protocol v5 Providers
  • Combining Protocol v6 Providers
  • Translating Protocol v5 to v6
  • Translating Protocol v6 to v5

  • Resources

  • Tutorial Library
  • Certifications
  • Community Forum
    (opens in new tab)
  • Support
    (opens in new tab)
  • GitHub
    (opens in new tab)
  • Terraform Registry
    (opens in new tab)
  1. Developer
  2. Terraform
  3. Plugin Development
  4. Combining and Translating
  5. Translating Protocol v6 to v5
  • Plugin Mux
  • v0.7.x
  • v0.6.x

ยปTranslating Protocol Version 6 to 5

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

Use this package to:

  • Migrate individual resources and data sources from terraform-plugin-sdk/v2 to terraform-plugin-framework over time, while maintaining Terraform CLI 0.12 and later compatibility.
  • Develop with terraform-plugin-framework, but support Terraform CLI 0.12 and later.

Compatibility

Protocol version 5 provider servers are compatible with Terraform CLI 0.12 and later.

The following provider server implementations are supported:

  • terraform-plugin-framework: A higher-level SDK that makes Terraform provider development easier by abstracting implementation details.
  • terraform-plugin-go tf6server: A lower-level SDK to develop Terraform providers for more advanced use cases.

Requirements

Downgrading provider servers from protocol version 6 to protocol version 5 will return an error if there are protocol version 6 features that are in use that are not available in protocol version 5. Refer to the protocol version 6 documentation for more information.

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

Code Implementation

Use the tf6to5server.DowngradeServer() function to wrap a provider server. For most providers, this is in the provider main() function of the root directory main.go file or where tf5muxserver is implemented in the codebase, if applicable.

The following example downgrades a terraform-plugin-framework provider.

downgradedFrameworkProvider, err := tf6to5server.DowngradeServer(
    context.Background(),
    providerserver.NewProtocol6(frameworkprovider.New(version)())
)

The following example uses tf5server to serve the downgraded provider directly.

err = tf5server.Serve(
    "registry.terraform.io/example/example",
    func() tfprotov5.ProviderServer {
        return downgradedFrameworkProvider
    },
)

The following example uses tf5muxserver to serve the downgraded provider while it is combined with other providers.

providers := []func() tfprotov5.ProviderServer{
    func() tfprotov5.ProviderServer {
        return downgradedFrameworkProvider
    },

    // Example terraform-plugin-sdk/v2 provider
    sdkprovider.New(version)().GRPCProvider,
}

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

Refer to the tf5muxserver 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 ProtoV5ProviderFactories field of TestCase to use the acceptance testing framework available in terraform-provider-sdk/v2/helper/resource.

The following example creates a test case for a downgraded provider.

resource.Test(t, resource.TestCase{
    // ... other TestCase fields ...
    ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error) {
        "example": func() (tfprotov5.ProviderServer, error) {
            return tf6to5server.DowngradeServer(
                context.Background(),
                providerserver.NewProtocol6(frameworkprovider.New("test")()),
            )
        },
    },
})

Refer to the acceptance tests documentation for more details.

Edit this page on GitHub

On this page

  1. Translating Protocol Version 6 to 5
  2. Compatibility
  3. Requirements
  4. Code Implementation
  5. Testing Implementation
Give Feedback(opens in new tab)
  • Certifications
  • System Status
  • Terms of Use
  • Security
  • Privacy
  • Trademark Policy
  • Trade Controls
  • Give Feedback(opens in new tab)