Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HCL syntax rules and Terraform single-file usage

Yes — in Terraform, a single .tf file can contain the full configuration, and that is perfectly valid.

General HCL syntax rules HCL is a declarative configuration language. Files use blocks and arguments:

block_type "label" { ... }
argument = value

Each block has a specific shape depending on the resource or provider. Strings are quoted: "us-east-1" Numbers and booleans are unquoted: 1, true Comments use:

...

// ... In Terraform specifically You can place:

terraform {} block provider {} block resource {} blocks variable {} blocks output {} blocks module {} blocks all in one file, or spread across many .tf files.

Practical rule Terraform merges all .tf files in the same directory into one configuration set. So:

One file is valid Many files are also valid The main thing is that the syntax must be correct and blocks must match Terraform schema For your current project Your current file already shows the right idea: everything can live in one file. The main issue was that the resource block was malformed:

wrong: resource ec2_instance "example" correct: resource "aws_instance" "example" Short answer Yes, Terraform can be entirely in one .tf file. HCL syntax is block-based, with quoted labels and assignment-style arguments. The general rule is: each Terraform object must use the correct block type and valid argument names. If you want, I can next help you turn this into a fully runnable AWS Terraform setup with:

in HCL:

whitespace is mostly ignored punctuation and block structure matter more than exact spacing

terraform init terraform plan terraform apply

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages