Implement terraform provider resource

From ubie-oss/terraform-provider-lightdash · View interactive version

Implement terraform provider resource is an AI agent skill from the GitHub repository ubie-oss/terraform-provider-lightdash. Implement Terraform Resources and Data Sources in `internal/provider` with comprehensive testing.

How to use this skill

Skill file

Implement Terraform Provider Resource

Description

This skill implements a new Terraform Resource or Data Source in the internal/provider directory using the hashicorp/terraform-plugin-framework. It includes comprehensive implementation steps, unit tests, and acceptance tests following the project's established patterns.

Input

The user should provide:

  1. Type: Resource or Data Source.
  2. Name: (e.g., lightdash_project_agent).
  3. Schema: List of attributes (name, type, required/optional/computed).
  4. API Client Method: Which api.Client method(s) to use for CRUD/Read operations.

Workflow

1. Implementation

2. Unit Testing

3. Acceptance Testing

Example Patterns

Resource Structure

package provider

import (
    "context"
    "github.com/hashicorp/terraform-plugin-framework/resource"
    "github.com/hashicorp/terraform-plugin-framework/types"
    "github.com/ubie-oss/terraform-provider-lightdash/internal/lightdash/api"
)

var _ resource.Resource = &exampleResource{}

type exampleResource struct {
    client *api.Client
}

type exampleResourceModel struct {
    ID   types.String `tfsdk:"id"`
    Name types.String `tfsdk:"name"`
}

func (r *exampleResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
    // ... Schema definition ...
}

func (r *exampleResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
    // ... Create logic ...
}

Acceptance Test

func TestAccExampleResource(t *testing.T) {
    if !isIntegrationTestMode() {
        t.Skip("Skipping acceptance test")
    }

    resource.Test(t, resource.TestCase{
        PreCheck: func() { testAccPreCheck(t) },
        ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
        Steps: []resource.TestStep{
            {
                Config: providerConfig + readAccTestResource("resources/example/010_create.tf"),
                Check: resource.ComposeTestCheckFunc(
                    resource.TestCheckResourceAttr("lightdash_example.test", "name", "value"),
                ),
            },
        },
    })
}

Reference

Assets

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.