Tips to develop Terraform code efficiently
Note
The code for this section is under the chap03/error
directory in the GitHub repository of this book.
Before we conclude this chapter, we want to introduce two commands that help you develop Terraform code more efficiently. The first command, terraform fmt
, formats Terraform configuration files so that they follow a consistent format and indentation. Formatting makes the files more readable. However, it can also serve as an initial check, as Terraform reports some syntax errors.
The second command is terraform validate
. This command performs a syntax check and checks for internal consistency. For example, consider the following file, which contains some incorrect Terraform syntax:
chap02/error/error.tf
data "google_compute_zones" "available" { region = var.region} data "google_compute_zones" "available" { region = var.region }
First, run terraform fmt
, which reports an error stating...