Locals Block
The locals block allows defining computed values for the workspace. Unlike variable blocks, locals cannot be overridden from the command line—they are computed from other values (variables, predefined values, or expressions).
Scope: Workspace locals are available to all projects in the workspace and can be referenced in workspace-level blocks (extensions, targets) and project-level blocks.
Usage
Locals are referenced using the local.<identifier> syntax. They can reference:
- Workspace variables:
var.config - Predefined variables:
terrabuild.branch_or_tag - Other locals:
local.other_local - Functions and expressions
Example Usage
Simple Local
locals {
app_name = "terrabuild"
version = "1.0.0"
}Computed from Variables
variable environment {
default = "dev"
}
locals {
image_tag = var.environment + "-" + terrabuild.branch_or_tag
registry = "ghcr.io/myorg"
}Complex Expressions
variable config {
default = "Debug"
}
locals {
# Build image tag from multiple sources
full_tag = var.config + "-" + terrabuild.branch_or_tag
# Registry path
registry = "ghcr.io/myorg"
# Computed from other locals
base_image = local.registry + "/base:" + local.full_tag
}Using in Extensions
locals {
dotnet_version = "8.0"
node_version = "22"
}
extension @dotnet {
container = "mcr.microsoft.com/dotnet/sdk:" + local.dotnet_version
}
extension @npm {
container = "node:" + local.node_version
}Multiple Locals Blocks
You can define multiple locals blocks in the same file. All identifiers must be unique across all blocks:
locals {
app_name = "api"
}
locals {
version = "1.0.0"
}
# Both can be used:
# local.app_name and local.versionLast updated on