swissshepherd

section_presence rule

Owns the structural integrity of a doc file: presence, order, and recognition of level-2 sections. Configuration comes from two places — the type block declares which sections may appear and in what order, and the check "section_presence" block toggles enforcement.

Type-side configuration

On the type block, list the sections this type may contain, in the order they must appear:

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

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

  region_aware = true
}

The list is exhaustive: any level-2 heading in the doc that does not match a declared section is reported as unknown. This applies to canonical names too — leaving import off the list and then writing ## Import in the doc is an error, even though import is a canonical name.

Each section block accepts:

The order of section blocks IS the canonical doc order. A type with no section blocks (e.g. guide, index) skips this rule entirely.

Canonical section names

title, signature, example, arguments, attributes, timeouts, import — recognized by the parser and have fixed heading text by convention (e.g. arguments → ## Argument Reference, example → ## Example Usage). The type’s arguments_heading and attributes_heading change the text of those two ("Arguments" for functions, "Schema" in the tfplugindocs doc style, see doc-style.md); findings name the configured text. In the reference doc style, any heading beginning with Argument or Attribute is also read as that section.

Custom section names

Any other lowercase snake_case identifier opts the type into a non-canonical H2 section. By default, the heading text is derived by title-casing the snake_case name. Custom headings are matched case-sensitively. Set heading_text to match a different exact heading, including capitalization. The value is the parsed heading text, without ## or Markdown formatting. For example:

type "ephemeral" {
  schema_kind   = "ephemeral"
  website_paths = ["website/docs/ephemeral-resources/{name}.html.markdown"]
  title_prefix  = "Ephemeral"

  section "title"       { required = true }
  section "example"     { required = true }
  section "arguments"   { required = true }
  section "attributes"  { required = true }
  section "usage_notes" {}    # → ## Usage Notes
  section "iam_permissions" { heading_text = "IAM Permissions" }
}

type "action" {
  schema_kind   = "action"
  website_paths = ["website/docs/actions/{name}.html.markdown"]
  title_prefix  = "Action"

  section "title"                 { required = true }
  section "example"               { required = true }
  section "dependency_management" {}    # → ## Dependency Management
  section "arguments"             { required = true }
}

[!WARNING] A custom section whose heading, from heading_text or title-cased from its name, matches a canonical section (including the Argument and Attribute prefixes in reference style) or another custom section’s heading is a config error. The parser would never record such a heading as the custom section, so the section could never be found.

[!Note] heading_text is only supported for custom sections, not canonical names. Use the type’s arguments_heading and attributes_heading for those two canonical sections. As with other sections, an explicit custom heading participates in presence and order checks at its declared position.

Check-side configuration

check "section_presence" {
  enforce_order          = true   # default
  allow_unknown_sections = false  # default
}

Schema-driven Timeouts

When a schema is loaded, the schema’s timeouts block decides whether the section is required, overriding the type’s required/forbidden flag for timeouts. A schema-configured timeouts block missing from the doc is an error; a documented timeouts section with no schema configuration is also an error.