How to Convert HCL to TOML
Input Your HCL Configuration
Paste your HCL/Terraform configuration or upload a .tf, .hcl or .tfvars file. Any HCL works, not only Terraform: resources, variables, outputs, locals, provider settings and your own block types are all read the same way.
Read the TOML
Shortly after you stop typing, the file is read with the HCL parser and written as TOML that tools like Cargo or Hugo can read. Each block becomes an array of tables named after its labels, and references such as var.instance_type are kept as text rather than worked out:
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = var.instance_type
price = 14.50
ingress {
from_port = 80
}
ingress {
from_port = 443
}
}[[resource.aws_instance.web]]
ami = "ami-0c55b159cbfafe1f0"
instance_type = "${var.instance_type}"
price = 14.50
[[resource.aws_instance.web.ingress]]
from_port = 80
[[resource.aws_instance.web.ingress]]
from_port = 443Download or Copy TOML
Copy the converted TOML to your clipboard or download as a .toml file for use in your projects.
Frequently Asked Questions
Why convert HCL to TOML?
Mostly to reuse values that live in Terraform files somewhere else: a Rust tool that reads its settings with Cargo-style TOML, a Hugo site, or a Python script using tomllib. Converting is quicker than retyping a long variable block by hand, and it is a handy way to see how Terraform nests its labels.
How are blocks like resource "aws_instance" "web" written in TOML?
The block type and its labels become the table name, and the block itself becomes an array of tables, so resource "aws_instance" "web" turns into [[resource.aws_instance.web]]. Arrays are used because HCL lets the same block appear more than once; two ingress blocks inside a resource come out as two [[resource.aws_instance.web.ingress]] entries. This is the same shape Terraform uses in its own .tf.json files.
Are variables, references and ${...} templates evaluated?
No. The page reads the file but never runs it, so var.region, aws_instance.web.id, function calls and templates such as "web-${var.env}" are written as strings in the ${...} form Terraform uses in .tf.json files. A literal $${ in a string stays escaped, so it still reads as plain text if it ever goes back into Terraform.
Will my numbers and strings change?
Values are copied, not retyped. A number such as 8901240544102066246 or -9223372036854775808 stays a bare TOML integer with every digit, and 14.50 keeps its trailing zero. A whole number past 64 bits, which TOML cannot hold, is written as a string with all its digits and a note. Strings are escaped for TOML, heredocs become ordinary strings with \n line breaks, and null values are left out because TOML has no null. Comments are not carried over.
What happens if my HCL has a mistake in it?
Nothing is written. Instead you get the line and column of the first problem with the line shown underneath, for example an argument with = but no value or a block that is never closed. If you paste JSON, YAML or TOML by mistake, the page says which format it looks like and points you to the converter for it.
Is my Terraform file uploaded anywhere?
No. The HCL parser runs in your browser, so the file you paste or upload is converted on your own machine and is not sent to a server. Nothing is kept either: reload the page and the editor starts empty.
Going the other way? The TOML to HCL converter turns TOML back into HCL. To check or tidy a Terraform file first, try the HCL Validator or the HCL Formatter, and for the .tf.json form use HCL to JSON.
Related Tools
HCL to JSON
Convert HashiCorp Configuration Language (Terraform) to JSON format
JSON to HCL
Convert JSON to HashiCorp Configuration Language for Terraform
HCL Formatter
Format and beautify HCL/Terraform configuration files with proper indentation
HCL Validator
Validate HCL/Terraform syntax and structure with error detection
HCL Fixer
Fix broken HCL/Terraform files automatically, repair syntax errors, missing braces, and malformed blocks
HCL to YAML
Convert Terraform HCL configuration to YAML format