Muxing
Muxing enables multiple underlying provider implementations to exist within the same logical provider server via the terraform-plugin-mux Go module. Each underlying provider implementation serves different managed resources and data sources. Refer to the Combining and Translating documentation for full details about muxing configuration.
Use Cases
Use muxing when:
- You have an existing terraform-plugin-sdk based provider.
- The provider includes more than a few managed resources and data sources.
- You want to iteratively develop or release a version of your provider with only some of the managed resources and data sources migrated to the Framework.
Otherwise for simplicity, it is recommended to migrate directly to the framework without temporarily introducing muxing.
Requirements
- Ensure
github.com/hashicorp/terraform-plugin-sdk/v2
is upgraded to the latest version. For example, running thego get github.com/hashicorp/terraform-plugin-sdk/v2@latest
command. - Ensure existing acceptance testing is passing. Acceptance testing can be used to verify the muxing implementation before release.
Implementation
- Introduce a Go type implementing the Framework's
provider.Provider
interface. Refer to the provider definition section of the migration guide for additional details. - Implement the
provider.Provider
typeSchema
andConfigure
methods so it is compatible for muxing. The schema and configuration handling must exactly match between all underlying providers of the mux server. Refer to the provider schema section of the migration guide for additional details. - Introduce a mux server using terraform-plugin-mux functionality. This code eventually must be referenced by the codebase's
main()
function, which is responsible for starting the provider server. Refer to the Mux Server Examples section for additional details. - Introduce an acceptance test for the mux server implementation. Refer to the Testing Examples section for additional details.
- Ensure
github.com/hashicorp/terraform-plugin-mux
is added to the provider Go module dependencies. For example, running thego get github.com/hashicorp/terraform-plugin-mux@latest
command.
Mux Server Examples
Terraform 0.12 Compatibility Example
The following main.go
example shows how to set up muxing for a provider that uses Protocol Version 5 to maintain compatibility with Terraform 0.12 and later. The example also shows how to use the debug
flag to optionally run the provider in debug mode.
Terraform 1.X Compatibility Example
The mux server can be setup to break compatibility with Terraform 0.12 through 1.1.6, but enable Protocol Version 6 capabilities in the Framework provider, such as nested attributes.
The following main.go
example shows how to set up muxing for a provider that upgrades the terraform-plugin-sdk based provider to Protocol Version 6 to support those new features in the Framework provider. The example also shows how to use the debug
flag to optionally run the provider in debug mode.
Testing Examples
Protocol Version 5
The following acceptance test example would be included in the same Go package that defines the provider code to verify the muxing setup:
Protocol Version 6
The following acceptance test example would be included in the same Go package that defines the provider code to verify the muxing setup:
Tips
- Only acceptance tests for migrated managed resources and data sources require testing code updates as noted in the testing page of the migration guide.
Troubleshooting
PreparedConfig response from multiple servers
Muxed providers may receive a new error, such as:
If the terraform-plugin-sdk based provider was using Default
or DefaultFunc
, you must remove the usage of Default
and DefaultFunc
in that provider implementation. Transfer the logic into the provider ConfigureFunc or ConfigureContextFunc, similar to how it must be implemented in a terraform-plugin-framework based provider.