Skip to content

required-version

Reports a module none of whose terraform blocks sets required_version, on the terraform block, or on the start of main.tf when the module has no such block. Override files do not count.

Terraform language features and the state format change between versions, and a state file written by a newer version cannot be used by an older one. A constraint makes an incompatible version fail at the start with a clear message instead of in the middle of an apply.

To fix, set required_version in a terraform block.

Reported
terraform {
backend "s3" {}
required_providers {
aws = { source = "hashicorp/aws", version = "~> 5" }
...
hcl:
lint:
rules:
required-version: warn # off (default), warn, error

Enabled by the presets: hcl/tflint-recommended.

Suppress one line with sudsy-disable-next-line required-version in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
tflint terraform_required_version partial A module with no terraform block at all is not reported (it needs the other files of the module).