terraform-provider
CLAUDE.md is the reference for this provider: architecture, the steps of Adding a resource or data source, Testing (Go tests and Terraform native tests), Provider coding conventions and Commands. Read those sections before writing code, plus internal/services/<service>/CLAUDE.md for the service you touch when that file exists. This skill only adds what CLAUDE.md does not carry; when the two disagree, CLAUDE.md wins and this skill needs fixing.
Start from a sibling
Before writing a resource or data source, read the closest existing one in the same service (same API family and credential), its tests, its example and its template, and copy their shape. The service package already shows the client it uses (pd.Client, pd.AdminClient, pd.AdminKeyClient or pd.OAuthClient), its shared test helpers and its state-mapping style; a new file that diverges from its siblings is the most common review finding.
Go dependencies
Pin every new module to an explicit version, because @latest takes whatever was published last, pre-release or minutes-old release included, and the version should be a deliberate choice visible in review. List the versions, pick the most recent stable release, then tidy:
go list -m -versions github.com/author/dependency
go get github.com/author/dependency@vX.Y.Z
go mod tidy
Commit go.mod and go.sum together; make tidy-check (part of make) fails when they are not tidy. The Anthropic Go SDK has its own pin and bump rule in CLAUDE.md: do not bump it as part of a feature.
Terraform file names
Use snake_case for every new Terraform file (data_source.tf, resource.tf, versions.tf), because the docs templates and native tests reference these exact names. Two older examples still use data-source.tf; leave them unless the task is to rename them.
Documentation
docs/ is generated by make generate and published as is to the Terraform Registry:
- never edit
docs/by hand, since the next generation overwrites it; change the template undertemplates/instead; - maintainer documentation (release process, CI secrets, signing) goes at the repository root (
RELEASE.md,CONTRIBUTING.md), never indocs/ortemplates/, because everything there is public on the Registry.
Every template under templates/resources/ and templates/data-sources/ follows the same shape. Copy a sibling from the same subcategory and adapt it:
---
page_title: "anthropic_<name> Resource - anthropic"
subcategory: "<Category>"
description: |-
One-line description.
---
# anthropic_<name> (Resource)
One-line description, then any load-bearing behaviour (archive on destroy, write-only secrets).
> **API**: `POST/GET/DELETE /v1/<path>[/{id}]` (<API family>).
> **Auth**: Standard API key (`api_key` / `ANTHROPIC_API_KEY`).
> **Beta header**: `anthropic-beta: <header>` (or None).
> **Cost**: Free for management (or what is billed).
## Example Usage
{{ codefile "hcl" "examples/resources/<name>/resource.tf" }}
{{ .SchemaMarkdown | trimspace }}
## Import
Import an existing <name> using its ID:
terraform import anthropic_<name>.example <id>
For a data source: page_title: "anthropic_<name> Data Source - anthropic", the heading (Data Source), the example path examples/data-sources/<name>/data_source.tf, and no Import section. Reuse an existing subcategory value (grep -h '^subcategory' templates/*/*.tmpl | sort -u) rather than inventing a near-duplicate, because each distinct value becomes a group in the Registry sidebar.
Native tests
The layout of tests/ (root module, ../examples/... sources, the file-level test { parallel = true }, plan-only and mock_provider cases) is in CLAUDE.md, Terraform native tests. When writing a test file, these run block options are the ones this repository uses:
| Option | Default | Use |
|---|---|---|
| command | apply | plan for Admin API and OAuth resources, which have no test organization or CI token (see CLAUDE.md) |
| module | none | source = "../examples/<kind>/<name>", always the public example |
| variables | none | overrides for this run only |
| assert | none | one condition and error_message per check |
| expect_failures | none | a validation or check block that must fail |
| state_key | none | shares state between runs that source different modules |
When writing the test:
- assert exact values when they are deterministic (an input echoed back, a fixed enum) and presence (
!= "",length(...) > 0) for live API data; - assert on computed attributes or compare a data source with the resource that created its object, because an assertion on a required input only echoes the configuration back; under
command = plana resource's computed attributes are unknown, so a plan-only test asserts on configured values; - order
runblocks so that what a run references was created by an earlier one; destruction runs in reverse order; - keep real credentials out of test files: they come from the environment (mise loads
.env), and a test file only ever holds the dummy credential of a plan-only test.
Done
The change is ready to commit when make passes (it formats, lints, tests, installs and regenerates docs), make terraform-test passes (or you state which tests could not run for lack of credentials), pre-commit run -a passes with the new files staged (it skips untracked files), and docs/ shows the regenerated page with a non-empty subcategory.