swissshepherd

Field homes: one section per field, no repeats

Issue #111. This rule decides which reference section a field belongs in. It supersedes the field-home table in coverage-path-resolution.md §2 and the Optional+Computed exemption in argument-attribute-misplacement.md §3. Where earlier designs disagree with this page, this page wins.

Core rule

Every field at schema path P has exactly one home, and is listed only there.

Field at P Home
Required, Optional, or Optional + Computed Argument Reference
a child block whose subtree has any Required or Optional field Argument Reference
Computed-only, or a child block whose subtree has no Required or Optional field Attribute Reference; Argument Reference instead is allowed when allow_inline_read_only = true
any field of a ConfigUnknown block (configurable object-typed attribute) unknowable: either section
an argument only through Optional + Computed, listed in allow_either_section declared unknowable: either section

Two consequences, checked separately:

  1. Wrong section. A field listed only outside its home is reported with a move. This is the existing misplacement and home-section behavior, with Optional+Computed now counted as configurable.
  2. Repeated. A field listed in both P’s Argument Reference section and P’s Attribute Reference section is reported, whatever its home. Neither entry is “also fine”: the duplicate adds nothing, the Attribute Reference byline already says “in addition to the arguments above”, and duplicates drift (aws_media_packagev2_channel_group: `description` - The same as `description`).

In the tfplugindocs doc style the two homes are one section: every field is listed in ## Schema, under the group its schema flags call for (doc-style.md). A doc missing a field’s home section gets one warning per missing section instead of per-field findings (doc-style.md §3).

What changed and why

Optional+Computed fields used to have home “either”, so they could be listed in Attribute Reference, in Argument Reference, or in both. The flags say the user can set the field; that it can also be computed when unset is a default, not a second identity. It’s an argument. Its default behavior belongs in its Argument Reference description.

Child blocks follow the same change: a child block whose subtree has an Optional+Computed field, and no pure-configurable one, used to be “either”. It’s now an argument.

Optional+Computed that may be an output

Optional+Computed is sometimes not an input at all. terraform-provider-aws’s SDKv2 tftags.TagsSchemaComputed() is Optional+Computed and backs resource tags_all and data-source tags, but most of those fields are only ever set by the provider (hashicorp/terraform-provider-aws#50491: 44 data-source sites read tags as a filter, 188 don’t). Nothing in the schema or the doc tells the two apart, so a finding that names one fix would be wrong for the other.

A field that is an argument only through Optional+Computed (an Optional+Computed scalar, or a child block whose configurable subtree has no Required field and no Optional field that isn’t also Computed) therefore gets findings that name both fixes:

Its home is still Argument Reference: a correct tags - (Optional) filter in Argument Reference draws nothing. tags_all is an implicit attribute (below), so it’s never told to move. When the provider makes output-only fields Computed, their warnings stop with no change here.

What this gives up: an Optional+Computed field that really is an input, documented only under Attribute Reference, gets a warning instead of an error. It’s still reported.

allow_either_section

The warning is right until the schema is fixed, and in terraform-provider-aws that can take a long time (hashicorp/terraform-provider-aws#50497). A warning nobody can clear trains people to ignore warnings, so a provider can instead say which fields the schema can’t be trusted on: allow_either_section = ["data_source/tags"]. Each listed field then has home “either”, like a ConfigUnknown field: no move finding in either section, “keep one entry” for a repeat, and it must still be documented somewhere. The provider states the uncertainty in config, so swissshepherd isn’t guessing.

An entry applies only where the field is an argument only through Optional+Computed, so it can’t relax a Required or plain Optional field, such as a resource’s tags. A labeled entry under Attribute Reference keeps the strip-label finding, as for implicit_attributes. A subsection in Attribute Reference that documents one, labeled or not, still isn’t collapsed into “move this subsection”, since the field may be an output. Its presence is still checked wherever coverage defers: a block holding one isn’t left to the missing-section warning while Attribute Reference exists, and duplicate Argument Reference headings must list it unless the path’s Attribute Reference section does.

What it gives up, and nothing reports instead: an entry’s field that really is an input (a data source that filters on tags) documented only under Attribute Reference passes. Remove the entry when the schema marks the outputs Computed only (hashicorp/terraform-provider-aws#50581); the filters then keep their Optional+Computed flag and their Argument Reference home.

ConfigUnknown

ConfigUnknown stays “either”: the schema doesn’t say whether each field is configurable (see object-typed-attributes.md), so the home can’t be named without guessing. A repeat is still certain, so it’s reported, with a neutral fix.

Repeated-field finding

For each schema path P (sorted, excluding skip_blocks) whose Argument Reference section A and Attribute Reference section B both resolve (§4 of coverage-path-resolution.md), and each schema field F at P (attribute or child block) listed in both:

Home of F Fix in the message
Argument Reference remove the Attribute Reference entry
Argument Reference, only through Optional+Computed remove the Attribute Reference entry if it can be set; otherwise the Argument Reference entry, and fix the schema
Attribute Reference remove the Argument Reference entry
either (ConfigUnknown, computed-only with allow_inline_read_only = true, allow_either_section, or implicit_attributes) keep one entry

Message: argument "F" in block "P" is listed in both Argument Reference (line L1) and Attribute Reference (line L2); <fix>. attribute instead of argument when the home is Attribute Reference. Root fields omit in block.

Severity: error. The AGENTS.md default for a high-volume new check is a warning; it bends here by maintainer decision (“no repeats, ever”), with the provider’s findings fixed in the same terraform-provider-aws PR that bumps swissshepherd.

Scope and exclusions:

Deferrals (what stops reporting, and what reports it instead)

Case Before After
Labeled configurable field under Attribute Reference, also in Argument Reference labels misplacement: “move it to Argument Reference” (wrong: it’s already there) repeated-field finding. Misplacement treats it as a repeat, not a move.
Same, for every field of a subsection labels collapse: “move this subsection to Argument Reference” repeated-field findings per field. A subsection whose misplaced fields are all repeats doesn’t collapse.
Computed-only field labeled in Argument Reference, also in Attribute Reference labels: “Attribute Reference already documents it, so remove it from Argument Reference” repeated-field finding, same fix
Unlabeled configurable field in both sections nothing (outsideHome skipped it) repeated-field finding

Each row has a test that the repeated-field finding fires and the old finding doesn’t.

What stays unchecked