Terraform & IaC

Have You Built a Custom Terraform Provider in Go? Interview Guide with Video

How a custom Terraform provider works, how to build one in Go with the Terraform Plugin Framework, and how to answer the interview questions senior DevOps, SRE and platform engineers are asked, with a 2-minute video walkthrough.

Quick answer: A custom Terraform provider is a Go binary, built with HashiCorp's Terraform Plugin Framework, that Terraform Core talks to over local gRPC. It has three layers: the provider (authentication and a shared API client), data sources (read-only lookups) and resources (a schema plus Create, Read, Update and Delete methods that call your REST API). Terraform stores each resource's ID in state, so later runs can detect drift, update or delete it. You test locally by compiling the binary and pointing dev_overrides in ~/.terraformrc at it.
Build a Custom Terraform Provider in Go | Terraform Plugin Framework (2-Minute Tutorial) TechTalk with Vinod · 2:06 · Watch on YouTube

In senior DevOps, SRE and platform engineering interviews, one question now separates candidates quickly: "Have you ever built a custom Terraform provider in Go?" Most engineers can write HCL for AWS or Azure. Far fewer can explain what happens when a company's internal platform or proprietary REST API has no official provider, and how to fix that properly.

Without a provider, teams fall back on Bash scripts, manual console work and configuration drift. With one, the internal API becomes declarative, reviewable, version-controlled Infrastructure as Code. This guide explains how a custom provider works, shows the key Go code, and gives you strong interview answers. Watch the 2-minute walkthrough below first; it uses a course-provisioning API as the example.

When a custom provider is the right answer

  • An internal platform with a REST API, such as a developer portal, a provisioning service or a licence system, that teams still manage by hand.
  • A SaaS or vendor product with an API but no Terraform provider, or one that is missing the resources you need.
  • Glue scripts that keep breaking: local-exec and null_resource work at first, but cannot read state back or detect drift.

How Terraform talks to your provider

Terraform Core and each provider are separate programs. When you run terraform plan or apply, Terraform starts the provider binary and talks to it over local gRPC. The Terraform Plugin Framework implements that protocol for you, so your Go code only describes schemas and what each operation does.

A well-designed provider has three layers:

LayerWhat it doesExample
ProviderReads configuration, authenticates and builds one shared HTTP clientprovider "eduarn" { endpoint = ... }
Data sourcesRead-only lookups of objects Terraform does not managedata "eduarn_trainer" "lead" {}
ResourcesA schema plus Create, Read, Update and Delete against the APIresource "eduarn_course" "batch" {}

Building it in Go: the key pieces

1. Serve the provider

main.go hands your provider to the framework, which runs the gRPC server. The address is the source name users put in required_providers.

package main

import (
	"context"
	"log"

	"github.com/hashicorp/terraform-plugin-framework/providerserver"

	"example.com/terraform-provider-eduarn/internal/eduarn"
)

func main() {
	err := providerserver.Serve(context.Background(), eduarn.New, providerserver.ServeOpts{
		Address: "registry.terraform.io/eduarn/eduarn",
	})
	if err != nil {
		log.Fatal(err)
	}
}

2. Define the resource schema

The schema is the contract with HCL: which arguments are required, optional or computed by the API.

type courseModel struct {
	ID    types.String `tfsdk:"id"`
	Title types.String `tfsdk:"title"`
	Seats types.Int64  `tfsdk:"seats"`
}

func (r *courseResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
	resp.Schema = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"id":    schema.StringAttribute{Computed: true},
			"title": schema.StringAttribute{Required: true},
			"seats": schema.Int64Attribute{Optional: true},
		},
	}
}

3. Implement CRUD against the REST API

Create reads the plan, calls the API and writes the returned ID to state. Read, Update and Delete follow the same pattern.

func (r *courseResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
	var plan courseModel
	resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
	if resp.Diagnostics.HasError() {
		return
	}

	id, err := r.client.CreateCourse(ctx, plan.Title.ValueString(), plan.Seats.ValueInt64())
	if err != nil {
		resp.Diagnostics.AddError("Creating course failed", err.Error())
		return
	}

	plan.ID = types.StringValue(id)
	resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
}

One detail interviewers like: if Read gets a 404, call resp.State.RemoveResource(ctx). Terraform then knows the object was deleted outside Terraform and plans to recreate it, instead of failing.

4. Use it from HCL

terraform {
  required_providers {
    eduarn = {
      source = "eduarn/eduarn"
    }
  }
}

provider "eduarn" {
  endpoint = "https://api.internal.example.com"
}

resource "eduarn_course" "terraform_batch" {
  title = "Advanced Terraform"
  seats = 25
}

5. Test locally with dev_overrides

Run go install ., then tell Terraform to use your local binary instead of the registry by adding this to ~/.terraformrc (%APPDATA%\terraform.rc on Windows):

provider_installation {
  dev_overrides {
    "registry.terraform.io/eduarn/eduarn" = "/home/you/go/bin"
  }
  direct {}
}

Now run terraform plan and terraform apply directly; Terraform prints a warning that overrides are active. For CI, add acceptance tests with terraform-plugin-testing and run them with TF_ACC=1 go test ./....

How to structure your interview answer

  1. The problem: "We had an internal REST API with no provider, so changes were scripted and drifted."
  2. The architecture: Terraform Core talks to the provider binary over gRPC; we used the Plugin Framework in Go.
  3. The design: provider for auth and the HTTP client, data sources for lookups, resources with a schema and CRUD.
  4. State and drift: Create stores the API's ID in state; Read refreshes it so drift shows up in the plan.
  5. Delivery: local testing with dev_overrides, acceptance tests in CI, then a versioned release to a private or public registry.

Most-asked questions and strong answers

QuestionWhat they are checkingStrong answer
How does Terraform talk to a custom provider?Plugin architecture, beyond HCLTerraform Core launches the provider binary and calls it over local gRPC; the Plugin Framework implements the protocol.
What is inside a custom resource?Schema design and the full lifecycleA schema of required, optional and computed attributes, plus Create, Read, Update and Delete methods that call the API.
How is state used during apply and drift checks?ID persistence and reconciliationCreate saves the returned ID in state; Read refreshes it each run, and removes it on a 404, so Terraform can update, recreate or delete cleanly.
How do you test before publishing?A real developer workflowgo install, dev_overrides in ~/.terraformrc for local runs, and acceptance tests with terraform-plugin-testing in CI.
Plugin Framework or SDKv2?Current best practiceThe Plugin Framework for new providers; SDKv2 mainly for maintaining older ones.

Learn it hands-on

Teams that want to turn internal APIs into Infrastructure as Code can book corporate training with hands-on labs and mock interviews. For more tutorials, see the original guide on the EduArn blog and visit EduArn.

Frequently asked questions

Why do interviewers ask whether you have built a custom Terraform provider?

It shows whether you understand how Terraform works inside, including the gRPC plugin model, schemas, the CRUD lifecycle and state, rather than only writing HCL for existing providers. It also shows you can automate internal platforms that have no official provider.

What is the Terraform Plugin Framework?

It is HashiCorp's current Go SDK for building providers, resources and data sources. HashiCorp recommends it over the older SDKv2 for new providers. It serves the provider to Terraform Core over gRPC.

What is the difference between a provider, a data source and a resource?

The provider configures authentication and a shared API client. A data source reads existing objects without managing them. A resource owns an object's full lifecycle: create, read, update and delete, tracked in Terraform state.

What happens during terraform apply on a custom resource?

Terraform Core calls your provider over gRPC. Your Create method reads the planned values, calls the REST API, and saves the returned ID and attributes to state. On later runs, Read refreshes the object so Terraform can detect drift.

How do I test a custom provider locally?

Build the binary with go install, then add a dev_overrides block in ~/.terraformrc that maps the provider's source address to your Go bin folder. Terraform uses the local binary for plan and apply without publishing to a registry. Add acceptance tests with terraform-plugin-testing for CI.

Do I need to know Go well to build a provider?

You need solid Go basics: structs, interfaces, error handling, context and HTTP clients. The Plugin Framework handles the gRPC protocol for you, so most of the work is the schema and the API calls.

Learn Terraform & IaC hands-on with expert trainers

Fixing problems like this one is part of our Terraform & IaC training: live online classes for individuals and on-site corporate training for teams, with real projects and labs.

Training available in Hyderabad, Bangalore, Pune, Mumbai, Delhi, Chennai and online across India.