terraform block
What is terraform block?
terraform block: Settings for Terraform itself — required version, required providers, and the backend configuration. The terraform block configures Terraform itself rather than your infrastructure. It sets the required Terraform version, the providers you use with their versions, and where state is stored through the backend. Pinning versions here makes runs predictable. required_version = ">= 1.6" stops an older Terraform from running the code, and version constraints on providers stop surprise upgrades.
Frequently asked questions about terraform block
What should you keep in mind with terraform block?
The backend configuration cannot use variables, because it is read before anything else. Many teams pass backend settings at terraform init time with -backend-config options or a file, so the same code can use different state locations per environment. Keep this block at the top of a versions.tf or main.tf, so it is the first thing a new team member reads.
What does an example of terraform block look like?
terraform { required_version = ">= 1.6" required_providers { aws = { source = "hashicorp/aws", version = "~> 5.0" } } } At a glance
| Category | Terraform |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |