Write custom Terraform providers with Go
✓Works with OpenClaudeYou are a Go developer building custom Terraform providers. The user wants to create a functional Terraform provider that manages external resources via Go code.
What to check first
- Run
go versionto confirm Go 1.19+ is installed - Verify
terraform -versionshows Terraform 1.0 or later - Check that the provider name follows the pattern
terraform-provider-{name}in your project directory
Steps
- Create provider scaffolding with
terraform-plugin-frameworkby importinggithub.com/hashicorp/terraform-plugin-frameworkin yourmain.go - Define your provider struct implementing the
provider.Providerinterface withMetadata(),Schema(),Configure(), andResources()methods - Create resource structs for each manageable resource type, each implementing
resource.ResourcewithCreate(),Read(),Update(), andDelete()methods - Define Terraform schema using
schema.Schema{}with attributes mapped to your Go struct fields via struct tags liketfsdk:"field_name" - Implement the
Configure()method to initialize your API client from provider-level configuration (host, API key, auth tokens) - Build the provider binary with
go build -o terraform-provider-mynamein the root directory - Place the binary in
~/.terraform.d/plugins/registry.terraform.io/myorg/myname/1.0.0/linux_amd64/(adjust OS/arch) - Create a
terraform {}block in your test.tffile pointing to the local provider withrequired_providers { myname = { source = "myorg/myname" } }
Code
package main
import (
"context"
"flag"
"log"
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/provider/metaschema"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)
var version string = "1.0.0"
func main() {
var debug bool
flag.BoolVar(&debug, "debug", false, "set to true to run the provider with support for debuggers")
flag.Parse()
opts := providerserver.ServeOpts{
Address: "registry.terraform.io/myorg/myname",
Debug: debug,
}
err := providerserver.Serve(context.Background(), New(version), opts)
if err != nil {
log.Fatal(err)
}
}
func New(version string) provider.Provider {
return &myProvider{
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Terraform Skills
Other Claude Code skills in the same category — free to download.
Terraform Module
Create reusable Terraform modules with variables and outputs
Terraform State
Manage Terraform state with remote backends (S3, Azure, GCS)
Terraform Workspace
Configure Terraform workspaces for multi-environment management
Terraform Import
Import existing infrastructure into Terraform state
Terraform Testing
Write Terraform tests with Terratest and terraform test
Terraform CI/CD
Set up Terraform CI/CD with GitHub Actions and Atlantis
Terraform Security
Scan Terraform for security issues with tfsec and Checkov
Want a Terraform skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.