Before a provider can be used with Terraform, it must implement a gRPC server that supports Terraform-specific connection and handshake handling on startup. The server must then implement the Terraform Plugin Protocol.
The framework handles the majority of the server implementation details, however it is useful from a provider developer perspective to understand the provider server details at least at a high level.
The Terraform Plugin Protocol defines the compatibility between Terraform CLI and the underlying provider. It is versioned, with newer versions implementing support for enhanced provider functionality but also requiring newer Terraform CLI versions. The framework implements two versions of the protocol.
Provider developers must choose either version 6 or version 5 and should consistently use that one version across implementations.
Terraform and provider developers have multiple ways to interact with the provider server implementation:
Go language programs implement startup logic via a main
function. Conventionally, this is done in a main.go
file at the root of a project. The main
function must eventually call the framework functionality for managing provider servers in the providerserver
package.
An example main.go
file for starting a protocol version 6 provider server:
package main
import (
"context"
"flag"
"log"
"github.com/example-namespace/terraform-provider-example/internal/provider"
"github.com/hashicorp/terraform-plugin-framework/providerserver"
)
var (
// Example version string that can be overwritten by a release process
version string = "dev"
)
func main() {
opts := providerserver.ServeOpts{
// TODO: Update this string with the published name of your provider.
Address: "registry.terraform.io/example-namespace/example",
}
err := providerserver.Serve(context.Background(), provider.New(version), opts)
if err != nil {
log.Fatal(err.Error())
}
}
To configure the provider server for protocol version 5, set the providerserver.ServeOpts
type ProtocolVersion
field to 5
:
opts := providerserver.ServeOpts{
// TODO: Update this string with the published name of your provider.
Address: "registry.terraform.io/example-namespace/example",
ProtocolVersion: 5,
}
It is also possible to combine provider server implementations, such as migrating resources and data sources individually from terraform-plugin-sdk/v2 to the framework. This advanced use case would alter the main.go
code further. Refer to the Combining and Translating Providers page for implementation details.
Refer to the acceptance testing page for implementation details.
DebuggingRefer to the debugging page for implementation details.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4