Chapter 1 of 6 · 4 practices · 3 min · 3-question quiz
Structure and style
How to lay out files, name things and format code so every Terraform change is easy to read in a pull request.
Start: Use the standard file layout for every root module4 practices in this chapter
- 1Use the standard file layout for every root moduleWhen every configuration splits its blocks the same way, people find things without searching. The Terraform style guide recommends: As a configuration grows, split
main.tfby logical group such as… - 2Run fmt, validate and a linter before every commitFormatting arguments in a review is a waste of everyone's time. The style guide says to run
terraform fmtandterraform validatebefore each commit, ideally from a Git pre-commit hook, and to use… - 3Name resources with descriptive nouns, without repeating the typeA resource address already contains its type, so
aws_instance.web_server_instancesays "instance" twice. The style guide recommends descriptive nouns with underscores, and not repeating the… - 4Give every variable and output a type and a descriptionUntyped variables accept anything, so a typo in a
.tfvarsfile shows up as a confusing error deep in a resource, or not at all. The style guide says every variable needs atypeand a…
Check yourself on this chapter
3 questions, right here once you are signed in. Your progress is saved as you read.