Bootstrap FreeKB - Terraform - Define list using locals
Terraform - Define list using locals

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 54faf9 in the box below so that we can be sure you are a human.