Bootstrap FreeKB - Terraform - Define dictionary using locals
Terraform - Define dictionary using locals

Updated:   |  Terraform articles

A dictionary (key value pairs) can be defined in a locals block. Let's say you have the following files on your Terraform server.

├── locals.tf
├── modules.tf
├── outputs.tf
├── provider.tf
├── terraform.tfstate
├── variables.tf
├── child (directory, child module)
│   ├── data.tf
│   ├── outputs.tf
│   ├── resources.tf

 

For example, let's say locals.tf file has the following.

locals {
  dictionary = {
    foo = "Hello"
    bar = "World"
  }
}

 

And let's say your outputs.tf in the same directory as your main root module (main.tf) has the following.

output "my-dictionary" {
  value = local.dictionary
}

 

The terraform output command should return the following.

my-dictionary = {
  "foo" = "Hello"
  "bar" = "World"
}

 




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 4ca95e in the box below so that we can be sure you are a human.