Terraform · API Governance Rules

Terraform API Rules

Spectral linting rules defining API design standards and conventions for Terraform.

10 Rules error 1 warn 8 info 1
View Rules File View on GitHub

Rule Categories

terraform

Rules

warn
terraform-jsonapi-content-type
HCP Terraform API endpoints should use JSON API content type (application/vnd.api+json)
$.paths..content
error
terraform-operation-ids-present
All operations must have operationId defined
$.paths.*[get,post,put,patch,delete]
warn
terraform-operation-id-casing
Operation IDs should use PascalCase
$.paths.*[get,post,put,patch,delete].operationId
warn
terraform-path-kebab-case
URL path segments should use kebab-case or path parameters
$.paths
warn
terraform-bearer-auth
HCP Terraform API uses bearer token authentication
$.components.securitySchemes.*
warn
terraform-response-200-or-201
Non-delete operations should have 200 or 201 responses
$.paths.*[get,post,patch]
warn
terraform-delete-204
DELETE operations should return 204 No Content
$.paths.*.delete
warn
terraform-parameter-descriptions
Path and query parameters should have descriptions
$.paths..parameters[*]
warn
terraform-tags-required
Each operation should have at least one tag
$.paths.*[get,post,put,patch,delete]
info
terraform-pagination-parameters
GET list operations should support pagination parameters
$.paths.*[get]

Spectral Ruleset

Raw ↑
extends: spectral:oas
rules:
  terraform-jsonapi-content-type:
    description: HCP Terraform API endpoints should use JSON API content type (application/vnd.api+json)
    message: "{{description}}: {{value}} should be application/vnd.api+json"
    severity: warn
    given: "$.paths..content"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          properties:
            "application/vnd.api+json":
              type: object

  terraform-operation-ids-present:
    description: All operations must have operationId defined
    message: "Operation at {{path}} is missing operationId"
    severity: error
    given: "$.paths.*[get,post,put,patch,delete]"
    then:
      field: operationId
      function: truthy

  terraform-operation-id-casing:
    description: Operation IDs should use PascalCase
    message: "Operation ID '{{value}}' should use PascalCase (e.g., ListWorkspaces, CreateRun)"
    severity: warn
    given: "$.paths.*[get,post,put,patch,delete].operationId"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z][A-Za-z0-9]+$"

  terraform-path-kebab-case:
    description: URL path segments should use kebab-case or path parameters
    message: "Path segment '{{value}}' should use kebab-case"
    severity: warn
    given: "$.paths"
    then:
      function: pattern
      functionOptions:
        match: "^(\\/([a-z][a-z0-9-]*|\\{[a-zA-Z_]+\\}))*$"

  terraform-bearer-auth:
    description: HCP Terraform API uses bearer token authentication
    message: "Security scheme should be bearer type"
    severity: warn
    given: "$.components.securitySchemes.*"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          anyOf:
            - properties:
                type:
                  const: http
                scheme:
                  const: bearer
            - properties:
                type:
                  const: apiKey

  terraform-response-200-or-201:
    description: Non-delete operations should have 200 or 201 responses
    message: "Operation should define a 200 or 201 response"
    severity: warn
    given: "$.paths.*[get,post,patch]"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          properties:
            responses:
              type: object
              anyOf:
                - required: ["200"]
                - required: ["201"]

  terraform-delete-204:
    description: DELETE operations should return 204 No Content
    message: "DELETE operation should return 204 No Content"
    severity: warn
    given: "$.paths.*.delete"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          properties:
            responses:
              type: object
              required: ["204"]

  terraform-parameter-descriptions:
    description: Path and query parameters should have descriptions
    message: "Parameter '{{value}}' is missing a description"
    severity: warn
    given: "$.paths..parameters[*]"
    then:
      field: description
      function: truthy

  terraform-tags-required:
    description: Each operation should have at least one tag
    message: "Operation at {{path}} should have at least one tag"
    severity: warn
    given: "$.paths.*[get,post,put,patch,delete]"
    then:
      field: tags
      function: truthy

  terraform-pagination-parameters:
    description: GET list operations should support pagination parameters
    message: "List endpoints should support page[number] or page[size] parameters"
    severity: info
    given: "$.paths.*[get]"
    then:
      function: schema
      functionOptions:
        schema:
          type: object

Work with this as data

Every ruleset here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for spectral rules

4 MCP tools reach this
  • find_rulesBrowse and filter every ruleset in the catalog.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This ruleset
curl "https://apis.io/api/v1/rules/hcp-terraform-rules"
All spectral rules
curl "https://apis.io/api/v1/rules?limit=25"

Discovery needs no key. Ratings and market analysis are Pro.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.