Skip to content

hcl_path_matches

Same shape as the *_equals variants, but the asserted value is a regex matched against string values. Non-string matches produce a clear “value is not a string” violation.

OptionTypeRequiredDefaultDescription
if_presentbooleanfalseWhen true, a query returning zero matches is silently OK - only real matches that fail the op produce violations.
matchesstringyesRust-regex pattern to match against the value at path.
pathstringyesJSONPath expression rooted at $.

Plus the common paths, level, id, and when fields. This table is generated from the JSON Schema; option types and defaults are authoritative.

A Terraform required_version without a pessimistic constraint

Section titled “A Terraform required_version without a pessimistic constraint”

The rule fires on this repository:

main.tf
main.tf
terraform {
required_version = "1.0.0"
}

With this .alint.yml:

version: 1
rules:
- id: pin-terraform
kind: hcl_path_matches
paths: "main.tf"
path: "$.terraform.required_version"
matches: "^~>"
level: error

alint check reports:

Terminal window
--- main.tf --------------------------------------------------------------------
x error pin-terraform
value at path "1.0.0" does not match regex ^~>
Summary (1 violation):
x 1 error
0 passing * 1 failing

A Terraform required_version with a pessimistic constraint

Section titled “A Terraform required_version with a pessimistic constraint”

This repository is compliant:

main.tf
main.tf
terraform {
required_version = "~> 1.0"
}

With this .alint.yml:

version: 1
rules:
- id: pin-terraform
kind: hcl_path_matches
paths: "main.tf"
path: "$.terraform.required_version"
matches: "^~>"
level: error

alint check reports:

Terminal window
v All 1 rule(s) passed.