liveBook · Manning

Linter rule

As explained in Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu

A linter rule is a configurable static-analysis check that specifies a condition source or configuration must satisfy.

A linter rule is a configurable static-analysis check that evaluates source or configuration without running it. Rules enforce quality, style, or policy conditions rather than application logic. In Terraform, TFLint supplies rules through plugins, such as checks for variable descriptions, required types, required_version, and unused providers. section 7.3.3

Enable the Terraform plugin in .tflint.hcl, choose a preset, then add or exclude individual rules. The recommended preset enables a useful subset; the all preset enables more checks, after which specific rules can be disabled. section 7.3.3

Listing 7.17 TFLint Terraform plugin
plugin "terraform" {                                 #1
  enabled = true                                     #2
  preset  = "recommended"                            #3
}

Shows the minimal Terraform plugin configuration: enable the plugin and select the recommended rule preset. section 7.3.3

Running and tailoring rules

A Makefile can initialize plugins and run TFLint with `tflint --init` followed by `tflint`. Results identify the rule name and offending configuration, such as a missing required_version or an unused provider. For a deliberate exception, place `# tflint-ignore: aws_instance_invalid_type` immediately before the accepted instance type. Cloud plugins extend rules to AWS, Azure, or Google configurations, while the OPA plugin supports custom policies. section 7.3.3 section 7.5

How Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu covers it

How deep it goes
Explains rule selection, plugin configuration, diagnostics, disabling, and inline exceptions, but not rule implementation internals.
Examples
Uses Terraform plugin presets, required_version and unused-provider diagnostics, cloud plugins, Makefile commands, and inline ignore comments.
What it assumes
Assumes Terraform configuration and introduces static analysis, plugins, presets, rule exclusions, and inline exceptions.
What you can do after
Operate TFLint by enabling plugins, selecting presets, interpreting findings, customizing rules, and recording narrow exceptions.
How it connects
Connects static analysis with TFLint, plugins, Terraform configuration, cloud providers, and custom policy enforcement.

Also explained in

Compare how 4 books explain linter rule →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu. The section links point to the parts of the book it draws on.