YAML to HCL Converter
Convert YAML to Terraform HCL (HashiCorp Configuration Language).
HCL has specific semantics for Terraform blocks. Review output before use.
About YAML to HCL Converter
Convert YAML configuration files into Terraform HCL (HashiCorp Configuration Language) instantly in your browser. The converter detects common Terraform block structures — resources, variables, outputs, providers, and more — and emits correctly formatted HCL attribute syntax, including nested map blocks and typed scalar values. No data is sent to a server; all processing happens locally. Always validate the output with terraform validate before applying, as HCL carries context-specific block semantics that a structural conversion alone cannot fully infer.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Porting a YAML-defined infrastructure config into Terraform syntax.
- Converting a Kubernetes-style manifest into HCL as a starting point.
- Producing HCL from a YAML source of truth during a migration.
- Getting the block syntax right for a structure you have in YAML.
- Comparing a YAML config against an existing HCL one.
Frequently Asked Questions
- What is HCL used for?
- HashiCorp Configuration Language — the syntax of Terraform, Packer, Consul and Nomad. It is designed to be both machine-generatable and human-editable, which is why it looks like a middle ground between JSON's structure and a scripting language's readability.
- How does a YAML mapping become an HCL block?
- A nested mapping becomes a block with braces and, where the schema expects them, labels: `resource "aws_instance" "web" { … }`. The labels are the part that cannot be inferred from YAML alone, since YAML has no equivalent of a block type with a name.
- What is the difference between an HCL block and an attribute?
- An attribute is `key = value` with an equals sign; a block is `type label { … }` with no equals. Terraform's schema decides which is which, so converting a nested mapping into the wrong one is a validation error rather than a stylistic difference.
- Are lists of objects handled?
- They become repeated blocks or a list of object literals depending on what the schema expects — Terraform's `dynamic` blocks exist precisely because those two forms are not interchangeable. A converted list is worth checking against the provider's documentation.
- Is HCL just JSON with nicer syntax?
- Terraform does accept a JSON form, and the two are equivalent for structure. What HCL adds is comments, multi-line strings with heredocs, expressions and interpolation — none of which JSON can express, which is why the JSON form is used for generated files and HCL for authored ones.
Common errors and gotchas
- Expecting a mechanical translation to be valid Terraform. HCL blocks have required labels and types that YAML does not encode.
- Losing the difference between an argument and a block, which HCL distinguishes and YAML does not.
- Producing attribute names that are not valid HCL identifiers.
- Assuming lists of maps become blocks, when the choice depends on the provider's schema.
- Emitting a bare list where the provider expects repeated named blocks, which Terraform rejects at plan time.