Local Values Flashcards
Is it a good idea to hard code tags?
No its not. It’s always best to centralize common values using variables
What are local values?
they are similar to variables in a sense that it allows you to store data centrally and can be referenced in multiple parts of configuration
Ex:
locals {
default = {
Team = “security-team”
}
}
tags = local.default
Why do we need local values instead of variables?
You can add expressions to locals, which allows you to compute values dynamically
Ex: locals {
instance_ids = concat(aws_instance.blue..id, aws_instance.green..id)
}
Locals vs Variables
Variable values can be defined in wide variety of places like terraform.tfvars, ENV variables, CLI, and so on
Locals are more of a private resource and have to change by directly modifying the code
Locals are often referred as just “locals”.
Locals are created by a locals block (plural) but if you reference the block you type local (singular)