aiven/terraform-provider-aiven/tf-resource-generator

Claude Code and agent skill by aiven/terraform-provider-aiven

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Generate new Terraform resources and data sources from YAML definitions and OpenAPI specs. Use when adding resources, creating YAML definitions, working with the Plugin Framework generator, or when the user asks about code generation.

Install

npx vskill@latest install aiven/terraform-provider-aiven/tf-resource-generator

SKILL.md

Terraform Resource Generator Skill

Generate new Terraform resources and data sources by learning from existing patterns in the codebase.

Tooling Rule (read first)

Always drive generation, formatting, and linting through Task:

  • task generate — generates code and runs task fmt automatically at the end
  • task fmt — formats Go, Terraform, and whitespace
  • task lint — runs all linters

Do NOT use go run ./generators/..., go generate, gofmt, goimports, golangci-lint, or make for these workflows. See AGENTS.md and Taskfile.dist.yml (run task --list) for the full command surface.

Overview

The generator creates Terraform resources by combining:

  1. OpenAPI Spec (openapi.json) - Aiven's API schema
  2. YAML Definitions (definitions/aiven_*.yml) - Configuration for resource generation

Note: This skill is the canonical reference for YAML syntax, adapter API, and implementation patterns. The tf-resource-migration skill builds on this for migrating existing SDK resources.

Generated outputs per resource:

  • zz_resource.go / zz_datasource.go - Terraform schema + internal schema
  • zz_view.go - CRUD operation handlers, ResourceOptions, DataSourceOptions
  • examples/resources/*/import.sh - Import command examples

Generated aggregated output:

  • internal/plugin/zz_provider.go - Provider resource/datasource registry

User Interaction Pattern

When the user requests a new resource, gather requirements BEFORE starting:

First Question

Settle which Terraform component is needed before writing YAML:

  • Both resource and data source - Full CRUD resource + read-only data source (the usual answer)
  • Resource only - Just the resource (create, read, update, delete)
  • Data source only - Read-only data source

If the request does not make it obvious, ask with AskUserQuestion. When running without a user to answer (autonomous mode), default to both and state the assumption in the summary instead of blocking.

Additional Information to Gather
  1. Resource name - What API resource/endpoint? (e.g., "MySQL database", "Kafka topic")
  2. Scope - Project-level, service-level, organization-level?
Discovery Process
  1. Update OpenAPI spec first by running task get-spec to get the spec matching the pinned go-client-codegen
  2. Search OpenAPI spec for operation IDs
  3. Show the user what you found and ask for confirmation
  4. Find similar resources in definitions/ and show them
  5. Clarify specifics if needed (composite ID, fields to exclude/rename, custom modifiers)
When NOT to Ask

These rules skip the discovery questions, not the component question above: a lone read operation ID still leaves resource-vs-data-source open, so ask (or apply the autonomous default).

  • If the user provided specific operation IDs -> proceed
  • If the user provided a complete YAML definition -> proceed
  • If it's a modification to existing definition -> read the file and proceed
Confirmation Before Generation

Always summarize what you're about to create before proceeding.

Learning from Existing Resources

CRITICAL: Before creating a new resource, ALWAYS search for similar existing resources to learn patterns:

bash
# Find all YAML definitions
ls definitions/aiven_*.yml
# Find resources with similar client handlers
grep -l "clientHandler: service" definitions/aiven_*.yml
# Find resources with custom modifiers
grep -l "expandModifier: true" definitions/aiven_*.yml
# Find composite ID examples
grep -l "identityFields:" definitions/aiven_*.yml

Key files to reference:

  • definitions/.schema.yml - Complete YAML schema specification
  • definitions/aiven_*.yml - Real working examples
  • Existing generated code in internal/plugin/service/*/zz_*.go

Generation Workflow

1. Update OpenAPI Spec

Always start by downloading the API schema. It comes from the openapi.zip asset of the go-client-codegen release pinned in go.mod, so the spec and the client always match. To pick up a newer API, bump the client first (task update-client):

bash
task get-spec
2. Find the API Operations

Search OpenAPI spec for operation IDs:

bash
jq '.paths | to_entries[] | .value | to_entries[] | .value.operationId' openapi.json | grep -i "keyword"

Common patterns: ResourceCreate, ResourceGet, ResourceUpdate, ResourceDelete, ResourceList

3. Find a Similar Resource

Search definitions/ for a resource with similar characteristics:

  • Same client handler (project, service, organization, etc.)
  • Similar ID structure (single vs composite)
  • Similar operations (CRUD, list-based reads, etc.)

Read that YAML file to understand the pattern.

4. Create Your YAML Definition

File: definitions/aiven_my_resource.yml

IMPORTANT: Definition files MUST have the aiven_ prefix. The filename (without .yml) becomes the resource name directly: aiven_my_resource.yml -> resource aiven_my_resource.

The generated package always lives at internal/plugin/service/<resource-name-minus-aiven-prefix-and-underscores> — e.g. aiven_my_resource -> internal/plugin/service/myresource, aiven_kafka_topic -> internal/plugin/service/kafkatopic. The directory, the Go package name, and the import alias in zz_provider.go are all the same string, derived from the filename.

Start minimal:

yaml
# yaml-language-server: $schema=.schema.yml
operations:
- id: OperationIDFromOpenAPI
type: create|read|update|delete
resource:
description: "..."
identityFields: [field1, field2]
clientHandler: project
5. Reference Fields

Add ref: to every field that references another resource, see Field References. Check other definitions too: a new resource can be the better target for their fields.

6. Generate and Iterate
bash
task generate # Generate code
task build # Build to check for errors
task lint # Check code quality

Review generated zz_*.go files. Refine YAML definition as needed.

YAML Definition Reference

Top-Level Fields

IMPORTANT: Always check definitions/.schema.yml for the complete, authoritative schema specification.

Common fields:

  • operations - Array of CRUD operations (id, type, resultKey, etc.)
  • resource / datasource - Configuration metadata
  • identityFields - Fields that compose the ID (e.g., [project, service_name])
  • clientHandler - API client type: project, service, organization, organizationbilling, etc.
  • remove - Fields to exclude from schema (exact paths or glob patterns)
  • rename - Field name mappings (API field -> Terraform field)
  • hoist - Lifts the children of a root API object to top-level attributes, e.g. hoist: {access_control: ["*"]}. Values are glob patterns of child names. A hoisted field's path is access_control/<child> for remove, and it can't be renamed. The internal schema marks each hoisted field with HoistedFrom: "access_control". d.Expand nests the marked fields after the modifiers, and d.Flatten lifts them before the modifiers, so the views and modifiers work with root fields only. d.HasChangeHoisted("access_control") reports a change of any of them. A child the API omits keeps its state, like a root field, so zero it in flattenModifier if that hides drift (see aiven_valkey_user). Cross-group pruning applies, e.g. valkey_* children are dropped from aiven_pg_user. Only root objects can be hoisted. A hoisted array is a set unless the schema sets type: arrayOrdered. A child that no declared update operation accepts is force-new: declare the update operation, even with disableView: true, and send the whole object (e.g. serviceuser.Update), so new children are updatable.
  • schema - Schema customizations (types, validation, behavior)
  • expandModifier / flattenModifier / readModifier - Enable custom Go modifiers
  • version - Schema version, the SDK SchemaVersion of a migrated resource (no state upgraders)
  • beta - Mark resource as beta (requires PROVIDER_AIVEN_ENABLE_BETA env var)
  • limitedAvailability - Mark resource as limited availability
  • legacyTimeouts - Enable SDK v2-style timeout blocks
  • requireServiceReady - List of accepted service types; gate CRUD on type and power state (see Service Readiness Gating)
  • userConfigDiscriminator - Split a oneOf user config into a block per type (see User Configs)
Resource Configuration
yaml
resource:
description: "..."
deprecationMessage: "..."
terminationProtection: true # Check field before delete
stateAttribute: state # Terraform attribute polled after Create/Update/Delete
refreshState:
desired: [ACTIVE, PENDING_PEER] # Call Read after Create/Update and wait for state convergence
failed: [ERROR, DELETED]
delay: "15s" # Wait before Read
removeMissing: true # Remove from state on 404
deleteState:
desired: [DELETED] # Poll Read after Delete until the resource reaches its terminal state

identityFields fields compose the string ID and are also the resource identity (Terraform 1.12+). Each must be a top-level string attribute, and Read must rebuild state from them. identityFieldsOptional lists the trailing identityFields not required for identity import; unset ones are left out of the resource and data source string IDs (foo/bar instead of foo/bar/baz). The generator validates these fields and documents identity import for every resource. String import examples use the full ID, including optional fields.

For a custom import handler that accepts additional string ID formats, set resource.importExample to a multiline shell example. It is used in both examples/resources/<type>/import.sh and the resource documentation. Keep alternative commands commented so copying the example imports the resource only once. This overrides documentation only; identityFields still defines the resource ID and identity import.

refreshState: true enables a post-Create/Update Read that completes on the first successful Read, retrying transient 404/403 errors. To also wait for an attribute value, set stateAttribute and a refreshState block with desired and optional failed instead — desired already includes that exists retry. Values within each list use OR semantics. A desired value completes the refresh, and any failed value stops it immediately. Values in neither list are treated as pending and retried until the operation timeout.

stateAttribute names a top-level computed-only attribute; the generator rejects anything else. When the value to wait for lives elsewhere — nested in a collection, spread over several attributes, or derived — keep refreshState: true and set ResourceOptions.RefreshStateCheck in init(). It runs after each Read of the post-Create/Update refresh only (never during plain Read, import, or a data source read), and its error decides what happens next: adapter.ErrRefreshStateFailed stops the refresh, and any other error means "not converged yet" and is retried with the same backoff as a transient Read error.

go
// The status lives inside a nested collection, out of reach of the declarative condition.
// Do not index with Get("file_info.0.file_status"): Get panics when the list is still empty.
func init() {
ResourceOptions.RefreshStateCheck = fileIsReady
}
func fileIsReady(d adapter.ResourceData) error {
list, _ := d.Get("file_info").([]any)
if len(list) == 0 {
return fmt.Errorf("jar file status is not ready: %q", "")
}
info, _ := list[0].(map[string]any)
status, _ := info["file_status"].(string)
switch status {
case "READY":
return nil
case "FAILED":
return fmt.Errorf("%w: jar file verification failed", adapter.ErrRefreshStateFailed)
}
return fmt.Errorf("jar file status is not ready: %q", status)
}

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
128
Repository forks
74
7-day trend score
24

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 19 Mar 2026, 8 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/aiven/terraform-provider-aiven/tf-resource-generator/badge)](https://verified-skill.com/skills/aiven/terraform-provider-aiven/tf-resource-generator)

Something wrong with this skill or its page? Tell us.