AboutBlogContact
DevOps & InfrastructureNovember 12, 2019 2 min read 223Updated: June 22, 2026

Building Custom HCL Providers with the Terraform Go SDK (2019)

AunimedaAunimeda
📋 Table of Contents

Building Custom HCL Providers with the Terraform Go SDK

It's 2019, and "Infrastructure as Code" (IaC) isn't just a buzzword anymore-it's the baseline. Terraform has won the tool war, but what happens when you need to manage a proprietary API or a niche service that doesn't have an official provider?

You build your own. Using the Terraform Plugin SDK, you can map Go functions to HCL resources and data sources.

The Anatomy of a Provider

A Terraform provider is a standalone binary that communicates with Terraform Core via RPC. The SDK handles all the heavy lifting of state management and diffing. Your job is to define the schema and implement the CRUD (Create, Read, Update, Delete) operations.

Defining a Resource

Here’s a look at how we define a simple "item" resource in a custom provider:

package myprovider

import (
    "github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func resourceItem() *schema.Resource {
    return &schema.Resource{
        Create: resourceItemCreate,
        Read:   resourceItemRead,
        Update: resourceItemUpdate,
        Delete: resourceItemDelete,

        Schema: map[string]*schema.Schema{
            "name": {
                Type:     schema.TypeString,
                Required: true,
            },
            "description": {
                Type:     schema.TypeString,
                Optional: true,
            },
        },
    }
}

func resourceItemCreate(d *schema.ResourceData, m interface{}) error {
    name := d.Get("name").(string)
    // Call your API here to create the resource
    d.SetId("unique-id-from-api")
    return resourceItemRead(d, m)
}

The Diffing Engine

The real magic is in how Terraform calculates the "plan". If you change the description in your .tf file, Terraform calls your Update function. If you change a field marked as ForceNew: true, Terraform knows it has to destroy and recreate the resource.

Why Go?

HashiCorp chose Go for a reason: static binaries, excellent concurrency, and a robust standard library for networking. In 2019, if you're doing DevOps, you're doing Go.

Stop manually clicking buttons in consoles. If it has an API, it should have a Terraform provider.


Aunimeda provides DevOps engineering and infrastructure services - CI/CD pipelines, containerization, cloud deployments, and monitoring setups.

Contact us to discuss your infrastructure needs. See also: DevOps Services, Custom Software Development

Read Also

The Operator Pattern: Extending the Kubernetes API (2017)aunimeda
DevOps & Infrastructure

The Operator Pattern: Extending the Kubernetes API (2017)

Moving beyond Deployments and Services. How to use Custom Resource Definitions (CRDs) and Controllers to manage complex, stateful applications in K8s.

Docker Compose vs Kubernetes: What Small Teams Actually Need in 2026aunimeda
DevOps & Infrastructure

Docker Compose vs Kubernetes: What Small Teams Actually Need in 2026

Kubernetes is powerful and over-engineered for most small products. Docker Compose is simple and hits its limits faster than you'd think. Here's where the actual boundary is, with real configs for both.

OpenTelemetry in Node.js: Distributed Tracing From Zero to Productionaunimeda
DevOps & Infrastructure

OpenTelemetry in Node.js: Distributed Tracing From Zero to Production

Logs tell you what happened. Traces tell you why it was slow. This is the complete guide to wiring OpenTelemetry into a Node.js microservices stack - auto-instrumentation, custom spans, trace propagation across HTTP and queues, and sampling strategies that won't bankrupt you.

Need IT development for your business?

We build websites, mobile apps and AI solutions. Free consultation.

DevOps Services

Get Consultation All articles