Terraform - Define list using locals

by
Jeremy Canfield |
Updated: July 20 2023
| Terraform articles
Lists can be defined in a locals block. Let's say you have the following files on your Terraform server.
├── modules.tf
├── locals.tf
├── outputs.tf
├── providers.tf
├── terraform.tfstate
├── variables.tf
├── child (directory, child module)
│ ├── data.tf
│ ├── outputs.tf
│ ├── resources.tf
And let's say locals.tf file has the following.
locals {
environments = ["dev", "stage", "prod"]
}
And let's say outputs.tf in the same directory as your main root module (main.tf) has the following.
output "my-environments" {
value = local.environments
}
The terraform output command should return the following.
my-environments = [
"dev",
"stage",
"prod",
]
Did you find this article helpful?
If so, consider buying me a coffee over at