Terraform Naming Convention Validator

Check resource, data, module, variable and output names. One of these rules is a correctness problem rather than a style preference: a hyphen in a name makes the resource impossible to reference.

Paste below, or drop a file anywhere on this panel

Or drop a file anywhere on this panel. Nothing is uploaded: the analysis runs in this tab.

The answer appears here

Paste on the left and press Check. Nothing leaves this tab.

Examples

Real input you can load into the tool above. Each one shows a different thing going wrong, because that is what the tool is for.

A hyphen in the name

The label is legal and the reference is not, so the resource can never be used

resource "aws_s3_bucket" "my-logs" {}

The same address twice

Terraform rejects it, and neither block looks wrong on its own when they are in different files

resource "aws_s3_bucket" "logs" {}
resource "aws_s3_bucket" "logs" {}

Common mistakes

These are the ones that fail silently. The config is accepted, nothing raises an error, and the consequence arrives later.

  1. Using a hyphen in a resource name

    The label accepts it and a reference cannot: aws_instance.my-server.id parses as a subtraction. The resource can be declared and never used, and the error appears in a different file from the cause.

    Instead:Use lower_snake_case. This is a correctness rule, not a style one.

  2. Naming a resource after its own type

    aws_s3_bucket.bucket puts the word twice in every reference, plan line and error message, and carries no information about which bucket this is.

    Instead:Name what distinguishes the instance, or main if there is only one.

  3. Hand-numbering copies of a resource

    web_1 through web_3 is the shape that becomes for_each later, and that refactor moves every resource in state. It gets more expensive the longer it is left.

    Instead:Use for_each with a map keyed by something meaningful. Keys survive additions and removals; count indices renumber.

One of these is a correctness rule and the rest are conventions

Terraform accepts almost any label. The constraints that matter come from how a name is used in a reference, and from what happens when the configuration grows.

A hyphen cannot be referenced

aws_instance.my-server.id parses as a subtraction, so a resource with a hyphen in its name can be declared and never referred to. The error appears in whichever file tries to reference it, not in the file that declared it, which is why this survives review. This is the one rule on this page that breaks a configuration rather than making it inconsistent.

An identifier must start with a letter or underscore

A leading digit is a parse error rather than a convention violation. Renaming to fix it is not free: Terraform sees a rename as a destroy and a create unless you add a moved block, so the fix has a state consequence.

Names that repeat their own type read badly everywhere

aws_s3_bucket.bucket appears in every reference, every plan line and every error message with the word twice. The type is already in the address, so the name should carry what distinguishes this instance. main is a better default than the resource kind.

A numbered name is a for_each refactor waiting to happen

web_1, web_2 and web_3 are the shape that becomes count or for_each later, and that refactor moves every resource in state. Doing it at three is a small change; doing it at thirty is a migration with a maintenance window. for_each keyed by something meaningful also survives additions and removals in a way count indices do not, because removing the second of three count items renumbers the third.

Duplicates are rejected and look fine individually

Two blocks with the same type and name are an error, and when they are in different files neither looks wrong on its own. Terraform names both locations, which helps, and only after you have run it.

What this cannot see

Whether the names are good, only whether they will work and whether they follow the common conventions. It also cannot see files you did not paste, so a duplicate split across two files is only found if both are here. Everything runs in your browser.

More terraform tools

Terraform Validator & Formatter Does it parse, and is it formatted? Terraform dynamic Block Generator It is ingress.value, not each.value Terraform check and precondition Generator A failed check does not stop the apply Terraform variables.tf Generator From the var. references you already wrote Terraform Unused Declaration Linter Dead variables, locals and data sources Terraform Atlantis YAML Generator when_modified misses your modules Terraform Function Tester and HCL Console terraform console, in a tab Terraform for Expression Tester Where do the keys collide? Terraform Interpolation Tester null becomes an empty string Terraform templatefile Tester Render it before you apply it Terraform Resource Count Calculator How many objects, not how many blocks Terraform count to for_each Converter With the moved blocks it needs Terraform moved Block Generator Rename without destroying Terraform state mv Command Builder No plan, no undo Terraform target Flag Builder And why to stop using it Terraform outputs.tf Generator Outputs are not sensitive by default Terraform Remote State Data Source Generator It grants read of the whole state Terraform Provider Block Generator docker is not hashicorp/docker Terraform .gitignore Generator and Checker .terraform* eats the lock file Terraform to OpenTofu Migration Checker The state is the part to watch Terraform tfvars to JSON Converter The JSON file wins Terraform Version Constraint Parser What ~> actually allows Terraform Resource Address Parser Quote it before the shell eats it Terraform cidrsubnet Calculator newbits is added, not the target Terraform Import Block Generator The id is not the name Terraform Lock File Viewer Why CI fails and your laptop does not Terraform Variables Checker A missing value hangs CI Terraform tfvars to Env Vars Converter Lists and maps have to be JSON Terraform Deprecated Syntax Checker What a current Terraform rejects Terraform State File Viewer Read it without uploading it Terraform Plan JSON Viewer It is not redacted Terraform HCL to JSON Converter And what the conversion loses Terraform Module Source Validator version only works for the registry Terraform Backend Config Decoder Is state actually locked?

Elsewhere on the site