swissshepherd

swissshepherd logo

A documentation linter for Terraform providers. swissshepherd compares a provider’s schema against its Markdown documentation and reports missing, phantom, misordered, mislabeled, or misformatted docs.

πŸ™ Source code: https://github.com/YakDriver/swissshepherd


Table of contents

What it checks

swissshepherd compares a Terraform provider’s schema against its markdown documentation and reports:

Installation

go install github.com/YakDriver/swissshepherd@latest

Requires Terraform in PATH when using provider_dir (for automatic schema generation).

Quick start

Create .swissshepherd.hcl in your provider repo root:

provider_source = "registry.terraform.io/hashicorp/aws"
provider_dir    = "."

Then run:

swissshepherd

That’s it. swissshepherd builds the provider, generates the schema, runs all checks, and reports findings.

Common invocations

# Check a single target (auto-detects type)
swissshepherd --target aws_iam_role

# Disambiguate when a name exists as both resource and data source
swissshepherd --target aws_instance --type resource

# Check all targets matching a prefix
swissshepherd --prefix aws_dms_

# Check all data sources
swissshepherd --type data_source

# Check a service's resources
swissshepherd --prefix aws_s3_ --type resource

CLI reference

swissshepherd [flags]
swissshepherd check [flags]
Flag Description
--config Config file path (default: .swissshepherd.hcl)
--schema-json Path to pre-generated terraform providers schema -json output
--provider-source Provider source address (e.g., registry.terraform.io/hashicorp/aws)
--provider-dir Path to provider source directory (triggers automatic build + schema generation)
--target Check a single named target
--type Restrict to a specific type (resource, data_source, ephemeral, function, list_resource, action)
--prefix Check all targets whose name begins with this prefix
--refresh-schema Regenerate cached schema even if schema_json file exists
--json Output results as JSON
--verbose Verbose logging (shows enabled checks, scoping, schema stats)
--version Print version and exit

CLI flags override config file values.

Output format

ERROR  [rule_name] resource_name (path/to/file.md:42): message
WARN   [rule_name] resource_name (path/to/file.md): message

Exit code 0 = all checks passed. Exit code 1 = one or more errors found.

Configuration

All configuration lives in a single HCL file. The full reference:

# .swissshepherd.hcl

# ─── Provider identity ───────────────────────────────────────────────────────

provider_source = "registry.terraform.io/hashicorp/aws"
provider_dir    = "."

# ─── Doc style ──────────────────────────────────────────────────────────────
# "reference" (default): ## Argument Reference / ## Attribute Reference with
# inline (Required)/(Optional) labels. "tfplugindocs": the ## Schema pages
# terraform-plugin-docs generates. See "Doc styles" below.

doc_style = "reference"

# ─── Schema caching ─────────────────────────────────────────────────────────
# When set, the schema is cached at this path (relative to provider_dir).
# First run builds the provider and writes here; subsequent runs reuse it.
# Use --refresh-schema to regenerate after provider code changes.

schema_json = "terraform-providers-schema/schema.json"

# ─── Global ignore lists ────────────────────────────────────────────────────

# Suppress all schema+doc rule findings for deprecated/removed stubs.
# File rules (frontmatter, file_check) still run.
ignore_contents_check      = ["aws_kms_secret"]
ignore_contents_check_file = "website/ignore-contents-check.txt"

# Map schema names to doc file names when they differ.
# Keys: plain "name" (all types) or "type/name" (scoped).
file_aliases = {
  "list_resource/aws_ebs_volume" = "aws_ec2_ebs_volume"
  "aws_alb"                      = "aws_lb"
}

# ─── Check blocks ───────────────────────────────────────────────────────────
# Each check block configures one rule. All rules are enabled by default.
# Add `enabled = false` to disable. See "Rules reference" for details.

Path resolution

All relative paths in the config (provider_dir, schema_json, *_file options) resolve against the current working directory β€” the same convention as terraform, go, and make. The config file’s location has no effect.

In practice: cd into the provider repo root and run swissshepherd from there:

cd terraform-provider-aws
swissshepherd --config .ci/swissshepherd.hcl

List files

Options ending in _file (ignore_targets_file, allow_subcategories_file, ignore_missing_file, skip_blocks_file, etc.) read one entry per line, merged with the inline list of the same name. Empty lines and lines starting with # are ignored.

Check blocks

Each check has at most one check "<name>" block; a second block with the same name is a load error. For per-target schema_docs settings, use override blocks inside the one block (see rules/schema_docs.md).

Checks are on by default, whether or not they have a block; a block that omits enabled keeps the check on, so it can change options without restating enabled = true. Only enabled = false turns a check off. prose_casing is the exception: it is opt-in and runs only with enabled = true.

Every check accepts severity = "error" or severity = "warning", which replaces the severity of every finding the check reports. Only errors fail the run, so "warning" reports a check’s findings without failing. On a check that mixes the two, such as schema_docs, it applies to all of them: "error" promotes the advisory warnings and "warning" demotes the errors. Without it, each finding keeps its own severity; anchors defaults to error and banned_glosses and prose_casing to warning. Any other value is a load error.

Rules reference

Overview

Rule Kind Description
anchors per-target In-page links (](#fragment)) resolve to a heading that exists in the file
banned_glosses per-file Flags configured abbreviation glosses/spell-outs (opt-in)
example_section per-target Example code block validation
file_check per-file File size, extension, and link style validation
file_match global File↔schema alignment: missing docs, orphan files, mixed layouts
frontmatter per-file YAML frontmatter field validation
import_section per-target Import section style and structure
prose_casing per-file Flags doc prose words and names whose casing or spacing should match a configured term but doesn’t (opt-in)
region_argument per-target Region argument presence for region-aware types
schema_docs per-target Schema coverage, ordering, description style, heading style, format, labels, deprecation, and bylines
section_presence per-target Section presence, order, and recognition of unknown level-2 headings
signature_section per-target Function signature validation
timeouts_section per-target Timeout actions match schema bidirectionally
title_section per-target Level-1 heading validation

Per-target rules run once per (resource, data source, etc.) and compare schema against parsed markdown. Per-file rules run on raw file bytes. Global rules run once per invocation.

The two largest rules β€” schema_docs and section_presence β€” have detailed reference docs in rules/. The smaller rules are documented inline below.


example_section

Validates example code blocks:

check "example_section" {
  allow_languages = ["terraform", "hcl"]  # default
}

file_check

Validates file-level properties.

check "file_check" {
  max_file_size             = 500000                                # bytes (default: 500KB registry limit)
  allow_extensions          = [".md", ".html.markdown", ".html.md"] # accepted extensions
  allow_registry_extensions = [".md"]                               # stricter set for docs/ layout
  inline_links              = true                                  # flag reference-style [ref]: url links
}

When inline_links is enabled, reference-style link definitions ([label]: url) are flagged with a suggestion to use inline [text](url) style instead.


file_match

Validates file↔schema alignment (runs once per invocation):

check "file_match" {
  require_doc    = true   # default: true
  require_schema = true   # default: true
  mixed_layout   = true   # default: true

  ignore_missing      = ["aws_alb", "aws_alb_listener"]       # no doc required
  ignore_missing_file = "website/ignore-file-missing.txt"
  ignore_extra        = ["aws_removed_thing"]                  # orphan doc OK
  ignore_extra_file   = "website/ignore-file-mismatch.txt"
}

The ignore_missing and ignore_extra lists suppress findings for specific targets. Use ignore_missing_file / ignore_extra_file for file-based lists.


anchors

Verifies that every in-page link (](#fragment)) resolves to a heading that actually exists in the same document. Renaming a block heading to the required `name` Block style changes its anchor slug (to name-block), and β€œSee below” links left pointing at the old slug (#name) become dead links that render silently on the Terraform Registry.

check "anchors" {
  enabled  = true
  severity = "error" # optional; "error" (default) or "warning"
}

The rule validates link fragments found anywhere in the document β€” Argument/Attribute bullets, Example Usage prose, callouts, any section β€” against the set of heading anchors the page generates. It reproduces GitHub’s slug algorithm, including underscore preservation (`ec2_configuration` Block β†’ #ec2_configuration-block) and the numeric suffixes appended to duplicate headings (#grpc-block, #grpc-block-1). An explicit HTML anchor, the id or name of an <a> element such as the <a id="nestedblock--part"></a> that tfplugindocs writes above each nested schema heading, is also a valid target; one inside a code span, fenced code block, or HTML comment is not. Only in-page # fragments are checked; external URLs and cross-file links are ignored. Each unresolved fragment is reported once, at its earliest line. Findings default to error; set severity = "warning" to soften. Like every check, it honors the standard scoping options.


banned_glosses

Flags abbreviation glosses and spell-outs anywhere in a document. A gloss is an abbreviation expansion like Amazon Resource Name (ARN). Anyone reading the docs already knows what an ARN, an S3 bucket, or a VPC is — glossing or spelling these out is noise. This check is entirely opt-in: it does nothing unless you configure a phrase→abbreviation map. There is no default list.

check "banned_glosses" {
  enabled = true

  banned_glosses = {
    "Amazon Resource Name"   = "ARN"
    "Simple Storage Service" = "S3"
    "Virtual Private Cloud"  = "VPC"
  }

  skip_frontmatter = true   # optional; default false
  severity         = "error" # optional; "error" or "warning" (default "warning")
}

For each configured pair it flags both forms and recommends the abbreviation:

The bare abbreviation (ARN) on its own is always accepted and never flagged. An optional leading Amazon /AWS on the phrase, and an optional Amazon /AWS inside the parenthetical (Amazon Simple Storage Service (Amazon S3)), are recognized. A trailing plural is tolerated (Amazon Resource Names β†’ ARNs).

The scan covers the whole document β€” descriptions, prose, callouts, and frontmatter β€” but skips fenced code blocks, inline code spans, and URLs so configuration and identifiers are left alone. Set skip_frontmatter = true to exclude the leading YAML frontmatter block (handy because subcategory values come from a fixed taxonomy and shouldn’t be rewritten). Findings default to warnings; set severity = "error" to fail the run. Each occurrence is reported with its line number. Like every check, it honors the standard scoping options (types, prefixes, targets, ignore_targets, ignore_prefixes).


prose_casing

Flags a word or multi-word name in doc prose whose casing or spacing should be a configured canonical form but isn’t β€” arn should be ARN, dynamodb should be DynamoDB, apigateway should be API Gateway. Unlike banned_glosses, which bans a spelled-out phrase in favor of its abbreviation, this check corrects the casing and spacing of a name that’s already the right name. It ships a small, vendor-neutral default list (ID, API, URL, JSON, CPU, and similar common initialisms); AWS- or provider-specific vocabulary (ARN, VPC, DynamoDB) is added via enforce_casing. This check is opt-in: unlike banned_glosses, it ships with a non-empty default list, so it requires an explicit enabled = true rather than defaulting on.

check "prose_casing" {
  enabled = true

  enforce_casing = ["ARN", "VPC", "KMS", "IAM", "DynamoDB", "API Gateway", "Auto Scaling group"]

  ignore_words = ["ami", "aws_emr_cluster/ssh"]

  skip_frontmatter = true    # optional; default false
  severity         = "error" # optional; "error" or "warning" (default "warning")
}

enforce_casing lists canonical forms to add to (or, for a word the default list already has, override the casing of) the built-in list. An entry can be several words: "API Gateway" matches api gateway, apigateway, and ApiGateway, because text may run a canonical form’s words together. It never matches text that splits a word the canonical form doesn’t, so "DataSync" doesn’t match data sync. Where a name is also an ordinary word, configure the phrase that identifies it ("Auto Scaling group", "EC2 Auto Scaling") rather than the bare word. Plurals and possessives ("Auto Scaling groups", "ID's") are separate entries. Words may contain only letters, digits, and underscores.

ignore_words removes an entry from the merged list before matching, compared without regard to case or spacing β€” a bare entry ("ami") removes it everywhere; a target/word entry ("aws_emr_cluster/ssh") removes it for one target only, the target given as a bare resource name or type/name.

Matching is case-insensitive and reports a finding whenever the matched text differs from the canonical form, so both Id and id are flagged as the same defect (want ID), and the canonical form is reproduced exactly as configured β€” including AWS’s mid-word capitals (DynamoDB, OAuth, iSCSI). A finding for a single word offers two possible fixes, since the check can’t tell which applies: use the canonical form, or wrap the word in backticks if it’s a literal β€” code, a value, or a field name (`ssh`, `Vpc`). A match spanning several words gets only the canonical form. The scan skips fenced code blocks, inline code spans, URLs, colon-delimited literals (arn:aws:ec2:…), and tokens glued to a hyphen, underscore, slash, or @ (execute-api, ~/.ssh/authorized_keys). Headings are scanned like any other text, but in Argument and Attribute Reference β€” the only sections where headings name blocks β€” a fix that would change the block a heading resolves to (capitalizing a bare block name, or respacing a title-style heading) is withheld and only backticks are suggested.

There is no inline, comment-based suppression for a single occurrence; ignore_words and the standard ignore_targets are the only escapes. See docs/rules/prose-casing.md for the full design rationale.


frontmatter

Validates YAML frontmatter at the top of each doc file. Requirements can come from both the check block (global) and the type block (per-type via frontmatter_require / frontmatter_forbid). Both sources are merged β€” a field required by either is enforced.

check "frontmatter" {
  # Require fields to be present
  require_subcategory = true
  require_page_title  = true
  require_description = true
  require_layout      = false  # legacy layout only

  # Forbid fields from being present
  forbid_subcategory    = false
  forbid_page_title     = false
  forbid_description    = false
  forbid_layout         = true   # registry layout
  forbid_sidebar_current = true  # always forbidden in modern docs

  # Subcategory allowlist (empty = anything goes)
  allow_subcategories      = ["S3", "VPC", "IAM"]
  allow_subcategories_file = "website/allowed-subcategories.txt"

  # Targets where subcategory: "" is acceptable
  allow_empty_subcategory_targets = ["arn_build", "arn_parse"]
}

import_section

Validates import section content and structure:

An import section with no code block passes when its first paragraph says the resource can’t be imported (β€œcannot import”, β€œcannot be imported”, β€œdoes not support import”, β€œdoes not currently support terraform import”).

check "import_section" {
  require_identity_section = true                     # default: true
  allow_languages          = ["terraform", "console"] # default; tfplugindocs style adds "shell"
  require_import_block     = true                     # default; false in the tfplugindocs style
}

region_argument

Validates that region-aware resources document the region argument. Only fires for types with region_aware = true in their type block (resources, data sources, ephemerals, and list resources by default).

check "region_argument" {
  ignore_resources      = ["aws_global_accelerator"]
  ignore_resources_file = "website/ignore-region.txt"
}

schema_docs

The primary rule. Validates argument and attribute documentation against the provider schema. Eight sub-checks: byline, coverage, deprecated, description, format, heading, labels, ordering. Coverage enforces the Required / Optional / Read-Only model at every depth of nesting and supports inline (Read-Only) labels via allow_inline_read_only. Every field has one home: Required, Optional, and Optional+Computed fields go in Argument Reference, computed-only fields in Attribute Reference. A field listed in both is an error (rules/field-homes.md). allow_either_section names Optional+Computed fields the schema marks Optional but that may be outputs (["data_source/tags"]); each may be documented in either section, not both (rules/schema_docs.md). It decides which section documents a block from headings alone, and checks every section against every block it documents; labels checks each section’s labels the same way. A list introduced by prose naming a block (β€œThe cloudwatch_logs object supports the following:”) documents that block, as a heading would; with nested_object_attributes, the indented sub-bullets under its bullets go with it. Fields of object-typed attributes (list(object({...})) and the like) are checked only with nested_object_attributes = true; with it off, a section naming such an attribute is accepted without comparing its bullets to the object’s fields. Deprecation of a cty object field isn’t checked in either direction, because the schema JSON has no deprecation flag for it; a Framework nested attribute’s fields are checked as usual (rules/object-typed-attributes.md). When a doc has no section a field may be documented in (no Argument Reference for an argument; no Attribute Reference for a Read-Only attribute, unless allow_inline_read_only lets it live in Argument Reference), one warning per missing section names the fields it leaves unchecked: no ## Argument Reference section, so 3 arguments (attributes, dn, object_classes) aren't checked against the schema (rules/doc-style.md).

See rules/schema_docs.md for the full configuration reference, sub-check details, and the schema model.


section_presence

Owns the structural integrity of a doc file: presence, order, and recognition of level-2 sections. Configured in two places β€” the type block declares which sections may appear and in what order; the check "section_presence" block toggles enforcement.

See rules/section_presence.md for the full configuration reference, custom-section conventions, and schema-driven Timeouts behavior.


signature_section

Validates function signature documentation:

No config options.


timeouts_section

Validates that documented timeout actions match the schema bidirectionally:

No config options.


title_section

Validates the level-1 heading (# Resource: aws_thing).

Checks:

check "title_section" {
  allow_prefixes = ["Resource", "Data Source", "Ephemeral", "Function"]
}

Doc styles

doc_style names the shape of the provider’s doc pages. It defaults to "reference", the hand-written shape of the AWS, Google, and Azure providers: # Resource: name, ## Argument Reference with (Required)/(Optional) labels on each bullet, ## Attribute Reference, ## Timeouts.

Set doc_style = "tfplugindocs" for docs generated by terraform-plugin-docs:

provider_source = "registry.terraform.io/hashicorp/cloudinit"
doc_style       = "tfplugindocs"

In that style:

Each default can be set in the config as usual. Custom templates that add sections, reorder them, or change titles are configured through the type blocks and allow_unknown_sections. See rules/doc-style.md for the design.

Path scoping

Every check block accepts path-scoping fields that control which targets the rule runs against. This is the primary mechanism for incremental rollout across a large provider.

check "schema_docs" {
  # Type axis: only these type names (empty = all)
  types = ["resource", "data_source"]

  # Name axis (OR'd together): prefix match OR exact match
  prefixes = ["aws_s3", "aws_appflow"]
  targets  = ["aws_instance"]

  # Deny list: always excluded, even when allowlists match
  ignore_targets      = ["aws_legacy_resource"]
  ignore_targets_file = "website/ignore-ordering.txt"
  ignore_prefixes     = ["aws_appstream"]
}

All four name-axis fields (prefixes, targets, ignore_targets, ignore_prefixes) support type/name notation for type-scoped entries:

check "schema_docs" {
  # Only match aws_thing when it's a data source, not a resource
  ignore_targets = ["data_source/aws_thing"]

  # Only match aws_s3_ prefixed data sources
  prefixes = ["data_source/aws_s3_"]
}

Plain entries (no /) match any type. Qualified entries (type/name or type/prefix) only match when the type matches.

ignore_targets turns a whole check off for a target. In schema_docs, an override block instead switches individual sub-checks for the targets it lists, e.g. coverage = false for a few resources whose schemas it can’t handle, keeping labels, ordering, and the rest. See rules/schema_docs.md.

Evaluation order:

  1. ignore_targets / ignore_prefixes β€” if matched, target is excluded unconditionally
  2. types β€” if non-empty, target’s type must be in the list
  3. prefixes / targets β€” if either is non-empty, target must match at least one; both empty = all names pass

Type system

swissshepherd ships with built-in type definitions for all standard Terraform documentation categories. Override any default or add new types in your config:

Built-in types

Type Schema kind Registry path (tried first) Legacy path Region-aware
resource resource docs/resources/{name}.md website/docs/r/{name}.html.markdown yes
data_source data_source docs/data-sources/{name}.md website/docs/d/{name}.html.markdown yes
ephemeral ephemeral docs/ephemeral-resources/{name}.md website/docs/ephemeral-resources/{name}.html.markdown yes
function function docs/functions/{name}.md website/docs/functions/{name}.html.markdown no
list_resource list_resource docs/list-resources/{name}.md website/docs/list-resources/{name}.html.markdown yes
action action docs/actions/{name}.md website/docs/actions/{name}.html.markdown no
guide none docs/guides/{name}.md website/docs/guides/{name}.html.markdown no
index none docs/index.md website/docs/index.html.markdown no

For each target, the checker uses the first path that exists. To use a different layout, override that type’s website_paths in the provider config. Type overrides replace the built-in type, so keep any other settings the provider needs.

Overriding a type

type "resource" {
  schema_kind   = "resource"
  website_paths = [
    "docs/resources/{name}.md",
    "website/docs/r/{name}.html.markdown",
  ]
  title_prefix = "Resource"
  region_aware = true

  section "title"      { required = true }
  section "example"    { required = true }
  section "arguments"  { required = true }
  section "attributes" { required = true }
  section "timeouts"   {}
  section "import"     {}
  section "signature"  { forbidden = true }

  frontmatter_require = ["description", "page_title"]
  frontmatter_forbid  = ["sidebar_current"]

  arguments_bylines = [
    "This resource supports the following arguments:",
    "The following arguments are required:",
    "The following arguments are optional:",
  ]
  attributes_bylines = [
    "This resource exports the following attributes in addition to the arguments above:",
  ]
}

Type fields

Field Description
schema_kind Schema accessor: resource, data_source, ephemeral, function, list_resource, action, none
website_paths Ordered list of path templates. {name} = provider-prefix-stripped target name
title_prefix Expected # <Prefix>: in the level-1 heading
title_format Exact level-1 heading text, {name} standing for the target name, e.g. "{name} (Resource)"; replaces the title_prefix check
arguments_heading Heading text of the arguments section (default: "Argument Reference"; functions "Arguments"; tfplugindocs style "Schema"). In the reference style, any heading beginning with Argument is also read as this section, so Arguments Reference works
attributes_heading Heading text of the attributes section (default: "Attribute Reference"); any heading beginning with Attribute also counts in the reference style
arguments_bylines Allowed paragraph texts under ## Argument Reference
attributes_bylines Allowed paragraph texts under ## Attribute Reference
allow_missing_arguments_byline Don’t require a byline paragraph
section "<name>" { ... } Declares a section in the doc structure. Order is the canonical doc order. Block fields: required, forbidden, and heading_text for an exact custom heading (default: title-cased section name). See section_presence for details.
frontmatter_require Fields that must be present in YAML frontmatter
frontmatter_forbid Fields that must be absent
region_aware Whether region_argument rule applies to this type

Heading templates

The block_heading_styles list controls which ### heading formats are recognized as block documentation within argument/attribute sections.

Placeholders

Placeholder Matches Example Extracted name
{Block} snake_case identifier network_interface network_interface
{Title} Title Case words (β†’ snake_case) Network Interface network_interface

Examples

Template Matches heading Extracted
`{Block}` Block `network` Block network
{Block} Configuration Block vpc_config Configuration Block vpc_config
{Block} Argument Reference filter Argument Reference filter
{Title} Credit Specification credit_specification

Note: goldmark strips backticks from inline code in headings, so ### `network` Block becomes network Block in parsed text.

The extracted name is the section’s key, and it alone decides which schema blocks the section documents: the full path, a shorter qualified path such as parent.block, or the bare block name. A heading in Argument or Attribute Reference that matches no template is reported, and its bullets aren’t checked against the schema; so is a heading whose key matches no schema block. See Coverage: which section documents a block.

Preferred style

Set prefer_block_heading_styles to emit warnings when a heading matches an accepted style but not the preferred one:

check "schema_docs" {
  block_heading_styles        = ["`{Block}` Block", "{Block} Block", "{Block}", "{Title}"]
  prefer_block_heading_styles = ["`{Block}` Block"]
}

Schema generation

When provider_dir is set, swissshepherd automatically:

  1. Builds the provider with go build
  2. Creates a temporary Terraform plugin directory
  3. Runs terraform init + terraform providers schema -json
  4. Uses the generated schema for all checks
  5. Cleans up temporary files

Caching

For large providers where the build takes minutes, set schema_json to cache:

provider_dir = "."
schema_json  = "terraform-providers-schema/schema.json"

First run builds and caches. Subsequent runs reuse the file instantly. Regenerate with --refresh-schema or delete the cached file.

Pre-generated schema

Skip the build entirely by providing a pre-generated schema:

swissshepherd --schema-json path/to/schema.json --provider-source registry.terraform.io/hashicorp/aws

Design

License

MPL-2.0