Contexts
A context is a reusable set of variables, secrets, and hooks. Attach it by stack labels or directly to selected stacks.
Attach by labels
Set auto_attach_selector to attach a context to stacks with matching labels.
Selector entries use AND: every key/value pair must match the stack’s labels.
For example, this context attaches only when both environment=production and
team=payments are present:
resource "gantrycd_context" "production" {
name = "production"
auto_attach_selector = {
environment = "production"
team = "payments"
}
variable {
key = "TF_VAR_environment"
value = "production"
}
}
A stack with both labels matches, even if it has additional labels. A stack
with only environment=production, or with team=platform, does not match.
Entries are not OR alternatives. An empty selector disables auto-attachment.
Attach directly
Use gantrycd_stack_contexts when a context is only for selected stacks:
resource "gantrycd_stack_contexts" "payments" {
stack_id = gantrycd_stack.payments.id
context_ids = [
gantrycd_context.shared.id,
gantrycd_context.production.id,
]
}
This resource owns the stack’s full list of directly attached contexts.
Which value wins
From lowest to highest precedence:
- Auto-attached contexts. A higher
auto_attach_prioritywins between them. - Directly attached contexts. A later ID in
context_idswins. - Variables set on the stack.
Protect secret contexts
Protect labels used by contexts that contain secrets. Anyone who can add a matching label to a stack could otherwise give that stack access to the secrets.
Hooks in a context run for every stack that receives it. They use the same fields and phases described in Hooks.