Text Processingflags: g

HCL / Terraform Variable Reference

Match Terraform / HCL references like `var.name`, `local.foo`, `module.x.output`, or `data.aws_ami.ubuntu.id`.

Try it in RegexPro →

Available in

Pattern

regexengine-agnostic
\b(?:var|local|module|data)\.[a-zA-Z_][\w\-]*(?:\.[a-zA-Z_][\w\-]*)*   (flags: g)

Raw source: \b(?:var|local|module|data)\.[a-zA-Z_][\w\-]*(?:\.[a-zA-Z_][\w\-]*)*

How it works

\b(?:var|local|module|data) anchors at one of the four namespace prefixes. \.[a-zA-Z_][\w\-]* matches the first segment after the prefix. (?:\.[a-zA-Z_][\w\-]*)* matches additional dotted accessors (deep references like `module.network.outputs.vpc_id`).

Examples

Input

vpc_id = module.network.vpc_id

Matches

  • module.network.vpc_id

Input

tags = merge(var.common_tags, local.env_tags)

Matches

  • var.common_tags
  • local.env_tags

Input

no references here

No match

Common use cases

  • Terraform dependency graph extraction
  • Refactor tooling (rename a variable across all files)
  • Linting for unused variables
  • Module-boundary auditing

Related patterns