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.