Terraform Advanced — Provider Architecture

less than 1 minute read

How Terraform communicates with providers under the hood.


Provider as a gRPC Plugin

┌──────────────┐     gRPC      ┌──────────────────┐
│   Terraform  │ ◄──────────►  │  Provider Binary  │
│   Core       │               │  (Go plugin)      │
└──────────────┘               └──────────────────┘
  • Terraform core and providers are separate binaries
  • They communicate over gRPC using the Terraform plugin protocol
  • Providers implement CRUD operations: Create, Read, Update, Delete

Provider Lifecycle

1. terraform init     → Downloads provider binary
2. terraform plan     → Calls Read() on each resource to check state
3. terraform apply    → Calls Create/Update/Delete as needed
4. terraform destroy  → Calls Delete() on each resource

Resource Schema

Every resource defines a schema:

func (r *ServerResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
    resp.Schema = schema.Schema{
        Attributes: map[string]schema.Attribute{
            "id": schema.StringAttribute{
                Computed: true,
            },
            "name": schema.StringAttribute{
                Required: true,
            },
            "size": schema.StringAttribute{
                Optional: true,
                Default:  stringdefault.StaticString("small"),
            },
        },
    }
}

What’s Next?

Choose between the Plugin Framework and SDKv2.

← When to Build Plugin Framework vs SDK →

Updated: