This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
make build- Complete build process: generates code from OpenAPI schema, compiles provider, and regenerates docsmake generate- Downloads Rootly OpenAPI schema and auto-generates client code and provider resourcesmake docs- Regenerates Terraform documentation from provider schemasmake test- Run unit testsmake testacc- Run acceptance tests (requiresTF_ACC=1environment variable)go build -o terraform-provider-rootly- Quick local build without code generation
# Build and install locally for testing
make build
mkdir -p ~/.terraform.d/plugins/terraform.local/local/rootly/1.0.0/darwin_arm64/
cp terraform-provider-rootly ~/.terraform.d/plugins/terraform.local/local/rootly/1.0.0/darwin_arm64/terraform-provider-rootly_v1.0.0Configure ~/.terraform.rc for local testing:
provider_installation {
filesystem_mirror {
path = "~/.terraform.d/plugins"
}
direct {
exclude = ["terraform.local/*/*"]
}
}
This provider is heavily auto-generated from Rootly's OpenAPI schema:
- Schema Download:
make generatefetches the latest OpenAPI spec from Rootly's S3 bucket - Schema Processing:
tools/clean-swagger.jscleans the schema,tools/generate.jsorchestrates generation - Client Generation: Uses
oapi-codegento generate Go client code inschema/directory - Provider Generation: Auto-generates data sources and resources in
provider/directory - Documentation: Auto-generates Terraform docs in
docs/directory
tools/generate-provider-tpl.js- Main provider configurationtools/generate-resource-tpl.js- Terraform resource implementationstools/generate-data-source-tpl.js- Terraform data source implementationstools/generate-client-tpl.js- Client method implementationstools/generate-workflow-tpl.js- Workflow-specific resourcestools/generate-tasks.js- Workflow task resources
Resources can be excluded from generation by adding them to the excluded object in tools/generate.js. This is useful for resources that need manual implementation or aren't ready for Terraform.
- Client Layer:
client/*.go- HTTP client implementations for each API resource - Provider Layer:
provider/resource_*.goandprovider/data_source_*.go- Terraform resource/data source implementations - Schema Layer:
schema/*.gen.go- Auto-generated Go structs from OpenAPI schema - Tests:
provider/*_test.go- Acceptance tests for resources
Provider supports:
api_host- Defaults tohttps://api.rootly.com, configurable viaROOTLY_API_URLapi_token- Required, configurable viaROOTLY_API_TOKEN
Workflow tasks are special resources with dynamic generation based on OpenAPI schema task definitions. They follow a pattern of workflow_task_<action>_<integration> and are automatically generated from the API schema.
The provider uses custom OpenAPI schema annotations to control Terraform resource generation behavior. These flags are processed in the JavaScript template files during code generation:
tf_diff_suppress_func- A custom diff suppressor function. Diff functions should be implemented in thegithub.qkg1.top/rootlyhq/terraform-provider-rootly/v5/internal/diffsuppressfuncpackage.tf_skip_diff- Prevents Terraform from detecting differences on a field. Adds aDiffSuppressFuncthat suppresses diffs when an old value exists. Used for sensitive fields like secrets or computed status fields. Deprecated. Usetf_diff_suppress_funcinstead withdiffsuppressfunc.Skip.tf_sensitive- Ensures that the attribute's value does not get displayed in logs or regular output.tf_force_new- Indicates that any change in this field requires the resource to be destroyed and recreated.tf_write_only- Used for arguments that handle secret values that do not need to be persisted in Terraform plan or state, such as passwords, API keys, etc. Write-only argument values are not sent to Terraform and do not persist in the Terraform plan or state artifact.tf_computed- Controls whether a field is computed by Terraform (true) or must be explicitly set (false). Affects JSON serialization and whether the field gets theomitemptytag.tf_include_unchanged- Forces a field to be included in update operations even if it hasn't changed. Bypasses the normald.HasChange()check. Used for fields the API requires in every update request.
These flags are added to OpenAPI schema properties and processed by tools/generate-resource-tpl.js to customize Terraform field behavior.
- Adding New Resources: Most resources are auto-generated. Add exclusions in
tools/generate.jsonly if manual implementation is needed. - Schema Updates: Run
make generateto pull latest OpenAPI schema and regenerate all code. - Documentation Updates: Run
make docsafter any provider schema changes. - Testing: Always run
make testaccbefore submitting changes. Tests require valid Rootly API credentials. - Local Testing: Use the local installation process above to test provider changes against real Terraform configurations.
The project uses semantic versioning with git tags and GoReleaser:
make version-show # Show current and next versions
make version-patch # Bump patch version (1.2.3 → 1.2.4)
make version-minor # Bump minor version (1.2.3 → 1.3.0)
make version-major # Bump major version (1.2.3 → 2.0.0)
make release-patch # Bump patch + create release
make release-minor # Bump minor + create release
make release-major # Bump major + create release- Version Bumping:
make version-*commands create and push git tags - Release Building: GoReleaser detects new tags and builds releases
- Version Injection: GoReleaser sets the version in
meta/version.goduring build - UserAgent: The provider dynamically uses the version for HTTP UserAgent headers
The version flows through: git tag → GoReleaser → meta.GetVersion() → provider.New() → RootlyUserAgent() → client.UserAgent
All acceptance tests MUST use randomized resource names via acctest.RandomWithPrefix("tf-...") or acctest.RandString(). Never use hardcoded names like name = "test" in test HCL configs — concurrent CI runs share the same API and hardcoded names cause 422 Name has already been taken failures.
Pattern to follow:
func TestAccResourceFoo(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-foo")
resource.UnitTest(t, resource.TestCase{
Steps: []resource.TestStep{{
Config: testAccResourceFooConfig(rName),
}},
})
}
func testAccResourceFooConfig(name string) string {
return fmt.Sprintf(`resource "rootly_foo" "test" { name = "%s" }`, name)
}- Use
constHCL strings only for data sources that read by slug/email (no create) - Keep name prefixes starting with
tf-(sweeper targets this prefix) - Watch for API field constraints: some fields have max length (e.g. sub_status: 20 chars) or character restrictions (e.g. secret: alphanumeric + underscore only)
- Generated Files: Files marked with "DO NOT MODIFY" headers are auto-generated. Changes should be made to templates in
tools/directory. - Schema Configuration:
schema/oapi-config.ymlcontrols OpenAPI code generation, including schema exclusions. - Release Process: New releases are triggered by Git tags and automatically published to Terraform Registry.
- Node.js Dependency: Code generation requires Node.js for JavaScript-based template processing.
- Version Management: Use
make version-*commands instead of manually creating git tags.