Great when:

  • some repeating value needs to be referenced in different places throughout the configuration
  • intermediary calculations needed
  • keep the code DRY and when it shouldn’t be exposed as a variable.

Example:

locals {
  http_port    = 80
  any_port     = 0
  any_protocol = "-1"
  tcp_protocol = "tcp"
  all_ips      = ["0.0.0.0/0"]
}

To access the value:

local.<NAME>