Terraform HCL Formatter and Validator

Open a Terraform folder or paste .tf files, format them the way terraform fmt does, and get syntax checks, variable and output tables and a module tree.

Chạy trong trình duyệt của bạn. Tệp không bao giờ rời khỏi thiết bị. Xem cách tự kiểm tra

…

Cách thực hiện

  1. 1
    Open the project

    Open a folder, select .tf and .tfvars files, or load the sample project.

  2. 2
    Choose formatting

    Keep the terraform fmt preset or limit blank lines.

  3. 3
    Check each file

    Read the diff and the syntax issues for the current file.

  4. 4
    Review the project

    Open the variables, outputs and modules tab.

  5. 5
    Fix references

    Add missing variables or remove unused ones from the notes.

  6. 6
    Export

    Download the formatted files as a ZIP, a .patch, or the variable and output tables as CSV.

Giới thiệu công cụ này

terraform fmt rewrites configuration files into the canonical HCL layout: two spaces of indentation for each nested block, one space around the equals sign, the equals signs of consecutive arguments aligned, and trailing comments lined up. This tool reproduces those rules in your browser from the same spacing table that HashiCorp's hclwrite package uses, so you can tidy files where the Terraform CLI is not installed or review the change before committing. Strings with ${...} and %{...} templates, heredocs written as <<EOT or <<-EOT, and comments starting with #, // or /* are copied unchanged. Like recent versions of fmt, it can also unwrap a string that contains only one interpolation, writing "${var.ami}" as var.ami, and rewrite legacy quoted variable types such as "string" or "list" as string and list(string). The validator parses every file into blocks and arguments and checks what terraform validate would complain about first: unknown top-level blocks, the wrong number of labels on resource, data, variable, output or module blocks, the same argument set twice, duplicate resources, outputs without a value and modules without a source. Open a whole folder and it also follows local module sources such as ./modules/network into the files you loaded and draws the module tree.

Variables, outputs and references

The project tab lists every variable with its type, default, description, sensitivity, the file and line where it is declared, and how many times it is referenced. Outputs are listed with their value expression and description, and resources and data sources with their provider prefix. References such as var.region, local.tags, module.network.vpc_id, data.aws_ami.x and aws_instance.web are checked against the declarations in the same folder. A value in a .tfvars file for a variable that is never declared is reported, and variables with no type, no description or no use get a note. Both tables can be exported as CSV.

Worked example

The sample project has main.tf, variables.tf, outputs.tf, prod.tfvars and modules/network/main.tf, all written without indentation. main.tf keeps its 33 lines; 18 change, 2 are added and 2 removed. Inside the aws_instance resource, ami, instance_type and count are aligned on one column, and "${var.ami_id}" is unwrapped to var.ami_id. tags = { is not aligned with them, because its value spans several lines, and the user_data heredoc is copied as written. In variables.tf the legacy type "string" becomes string. The project tab shows 7 variables, 3 outputs, 2 resources and 2 module calls: module.network resolves to the loaded folder, and module.eks is a registry module at version 20.8.4. The single warning is for owner in prod.tfvars, which no variable declares.

Limits

This is a static check, not terraform validate: provider schemas are not downloaded, so misspelt resource arguments and wrong value types are not found, and references are only checked against the files you loaded. The output matches terraform fmt for normal files, but unusual expressions may differ in spacing, and the result should not replace running the real CLI in your pipeline.

Ví dụ có lời giải

Sample project: main.tf 33 lines with 18 changed, "${var.ami_id}" unwrapped; 7 variables, 3 outputs, 2 modules; one warning for owner in prod.tfvars.

Tóm tắt

Câu hỏi thường gặp

Is the output the same as terraform fmt?

For ordinary configuration it should be: the indentation, spacing and alignment rules follow hclwrite, which terraform fmt uses. Run the real command in CI if you need a guarantee.

Why is one argument not aligned with the ones above it?

terraform fmt only aligns arguments whose value fits on the line. An argument such as tags = { that opens a multi-line value ends the group, and the lines after it start a new group.

Can it check a whole project with modules?

Yes. Use Open a whole folder. Files keep their relative paths, local module sources are matched to the loaded folders, and the module tree shows each call with its source and version.

Does it validate provider arguments?

No. It checks structure, labels, duplicates and references, but not provider schemas, because those would have to be downloaded from the registry.

What happens to heredocs and templates?

They are kept exactly as written, including their indentation. Only a string that is a single interpolation can be unwrapped, and that option can be turned off.

Are my files or secrets uploaded?

No. Everything, including .tfvars values, stays in your browser.

Hoàn toàn miễn phíKhông phí, không đăng ký
Tệp luôn riêng tưMọi thứ chạy trong trình duyệt của bạn
Dễ dùng bằng ngôn ngữ của bạnCó nhiều ngôn ngữ