AI Tools Compared

Building custom Terraform provider plugins requires writing Go code that conforms to the Terraform Plugin Framework’s provider schema, resource lifecycle methods, and validation patterns. AI coding assistants excel at this task because the framework follows consistent patterns, and quality AI tools understand schema definitions, state management, and test structure well enough to generate functional code that passes acceptance tests on first or second iteration.

Why Terraform Providers Suit AI Assistance

Terraform provider development involves repetitive, pattern-based code. Each resource requires a schema definition, Create, Read, Update, Delete (CRUD) handlers, and acceptance tests. These patterns are predictable enough that AI assistants trained on Go and the Terraform Plugin Framework can generate accurate implementations. The challenge isn’t complexity—it’s providing the AI with enough context about your custom system’s API structure and behavioral requirements.

Providers for proprietary APIs, internal systems, or less common platforms often lack good documentation or community examples. This is where AI shines: you describe your API’s endpoints, authentication method, and resource structure, and the AI generates boilerplate-free code that actually works.

AI-Assisted Provider Development Workflow

The most effective approach combines human design with AI implementation:

  1. Define your resource model and API endpoint structure
  2. Ask the AI to generate the provider schema for each resource
  3. Generate CRUD methods based on your API’s actual request/response format
  4. Generate acceptance tests that validate both creation and state management
  5. Run tests and iterate on any failures

This workflow typically requires 3-4 iterations per resource. The AI learns from test failures and refines implementations quickly.

Practical Example: Custom API Provider

Consider building a provider for a SaaS platform with a simple REST API:

POST /api/v1/projects - Create a project
GET /api/v1/projects/{id} - Get project details
PUT /api/v1/projects/{id} - Update a project
DELETE /api/v1/projects/{id} - Delete a project

You might provide this context to an AI assistant:

I'm building a Terraform provider for MyAPI. I need to create a resource called
"myapi_project" that maps to the MyAPI platform.

The API endpoints are:
- POST /api/v1/projects (creates a project, returns {id, name, description, status, created_at})
- GET /api/v1/projects/{id}
- PUT /api/v1/projects/{id} (updates name and description)
- DELETE /api/v1/projects/{id}

Authentication: Bearer token in Authorization header
Base URL: https://api.myapi.com

Terraform resource should support:
- name (required, string)
- description (optional, string)
- tags (optional, map of strings)

The API returns status codes: 200 (success), 404 (not found), 401 (unauthorized),
422 (validation error).

The AI can then generate the complete resource implementation, including error handling and validation.

Comparing AI Tools for Terraform Providers

Tool Best For Context Window Go Support Cost Speed
Claude Multi-resource providers, complex logic 200k tokens Excellent $3-20/month Fast
GPT-4 Quick implementations, debugging 128k tokens Very Good $20/month Very Fast
GitHub Copilot IDE-based development Varies Good $20/month Instant
Cursor Full provider scaffold 100k+ tokens Excellent $20/month Fast
Codeium Open-source providers Varies Good Free tier available Fast

Claude for Terraform Providers

Claude excels at provider development because it maintains excellent context across multiple resource definitions and understands the Terraform Plugin Framework deeply. Its 200k token context window means you can paste your entire API documentation, existing provider code, and multiple resource definitions in a single conversation.

Workflow:

  1. Paste your API documentation
  2. Ask Claude to generate the provider structure
  3. For each resource, provide the API endpoint details
  4. Claude generates schema, CRUD methods, and tests
  5. Run tests, share error output, iterate

Example cost: A complete 3-resource provider typically costs $0.15-0.30 in API usage.

Strengths:

GPT-4 for Provider Scaffolding

GPT-4 generates provider code quickly and is particularly useful for initial scaffolding and quick implementations. It’s faster than Claude for simple resources but sometimes struggles maintaining context across multiple complex resources.

Best for:

Limitations:

GitHub Copilot for IDE Integration

Copilot excels when you’re actively coding in your IDE. It provides instant completions for schema definitions, CRUD methods, and test boilerplate without switching contexts.

Strengths:

Limitations:

Workflow:

  1. Create provider scaffolding manually or with Claude
  2. Use Copilot for method completion and test generation
  3. Accept suggestions that align with your provider’s patterns
  4. Reject or modify suggestions that diverge from your architecture

Cursor for Full-Project Workflows

Cursor extends VS Code with AI capabilities across entire projects. It’s particularly valuable for Terraform provider development because it understands your full codebase and can generate implementations that align with existing patterns.

Advantages:

Use case: You’re adding a 5th resource to an existing 4-resource provider. Cursor analyzes your existing implementations, then generates the new resource with identical patterns and error handling.

Practical Implementation Guide

Setting Up Your Provider Structure

Start with a basic structure, optionally using the official Terraform Provider Scaffold:

terraform {
  required_providers {
    myapi = {
      source  = "example.com/mycompany/myapi"
      version = "~> 1.0"
    }
  }
}

resource "myapi_project" "example" {
  name        = "Example Project"
  description = "Created with Terraform"
  tags = {
    environment = "production"
  }
}

Generating the Resource Implementation

Provide the AI with your API contract and ask for the resource implementation:

// Generated by AI based on API specification
func (r *ProjectResource) Schema(ctx context.Context, req resource.SchemaRequest,
    resp *resource.SchemaResponse) {
  resp.Schema = schema.Schema{
    Description: "Manages a MyAPI project",
    Attributes: map[string]schema.Attribute{
      "name": schema.StringAttribute{
        Required:    true,
        Description: "The name of the project",
      },
      "description": schema.StringAttribute{
        Optional:    true,
        Description: "Project description",
      },
      "tags": schema.MapAttribute{
        Optional:    true,
        ElementType: types.StringType,
      },
      "id": schema.StringAttribute{
        Computed:    true,
        Description: "The project ID",
      },
      "created_at": schema.StringAttribute{
        Computed:    true,
        Description: "Creation timestamp",
      },
    },
  }
}

func (r *ProjectResource) Create(ctx context.Context, req resource.CreateRequest,
    resp *resource.CreateResponse) {
  var data ProjectResourceModel

  resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
  if resp.Diagnostics.HasError() {
    return
  }

  // Build API request
  createReq := map[string]interface{}{
    "name": data.Name.ValueString(),
  }

  if !data.Description.IsNull() {
    createReq["description"] = data.Description.ValueString()
  }

  // Call API
  var result ProjectResponse
  resp.Diagnostics.Append(r.client.Create(ctx, "/api/v1/projects", createReq, &result)...)
  if resp.Diagnostics.HasError() {
    return
  }

  // Map response to state
  data.ID = types.StringValue(result.ID)
  data.CreatedAt = types.StringValue(result.CreatedAt)

  resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}

Generating Acceptance Tests

Terraform provider testing requires acceptance tests that create real resources:

// AI-generated acceptance test
func TestAccProjectResource(t *testing.T) {
  resource.Test(t, resource.TestCase{
    PreCheck:                 func() { testAccPreCheck(t) },
    ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
    Steps: []resource.TestStep{
      // Create and Read testing
      {
        Config: testAccProjectResourceConfig("test-project", "A test project"),
        Check: resource.ComposeAggregateTestCheckFunc(
          resource.TestCheckResourceAttr("myapi_project.test", "name", "test-project"),
          resource.TestCheckResourceAttr("myapi_project.test", "description", "A test project"),
          resource.TestCheckResourceAttrSet("myapi_project.test", "id"),
        ),
      },
      // ImportState testing
      {
        ResourceName:      "myapi_project.test",
        ImportState:       true,
        ImportStateVerify: true,
      },
      // Update and Read testing
      {
        Config: testAccProjectResourceConfig("test-project", "Updated description"),
        Check: resource.ComposeAggregateTestCheckFunc(
          resource.TestCheckResourceAttr("myapi_project.test", "description", "Updated description"),
        ),
      },
      // Delete testing automatically occurs
    },
  })
}

func testAccProjectResourceConfig(name string, description string) string {
  return fmt.Sprintf(`
resource "myapi_project" "test" {
  name        = "%s"
  description = "%s"
}
`, name, description)
}

Common Pitfalls and Solutions

Schema mismatch with API: The AI generates a schema that doesn’t match your API’s actual fields. Solution: Provide complete API response examples as JSON, not just descriptions.

Missing error handling: Generated code doesn’t handle 422 validation errors or 401 auth failures appropriately. Solution: Explicitly ask the AI to handle specific HTTP status codes and API error response formats.

State lifecycle issues: Resources update locally but not on the remote API. Solution: Ensure the AI includes state refresh logic in Update and Read methods.

Test configuration generation: Acceptance tests fail because generated HCL doesn’t match actual provider syntax. Solution: Show the AI working examples from your provider’s test suite before asking for new tests.

Iterative Refinement Process

  1. Generate resource schema from API documentation
  2. Run terraform plan to validate schema syntax
  3. Generate Create method, test locally
  4. Generate Read/Update methods, test with terraform apply
  5. Generate acceptance tests, run with TF_ACC=1 go test
  6. Share test failures with AI, iterate until tests pass

Most providers reach production-ready status in 2-3 complete iterations per resource.

Performance Considerations

For AI-assisted development:

For most teams, a combination works best: Claude for initial architecture, Copilot for active development, and Claude again for complex bug fixes.

Built by theluckystrike — More at zovo.one