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 every stack with matching
labels:
resource "gantrycd_context" "production" {
name = "production"
auto_attach_selector = {
environment = "production"
}
variable {
key = "TF_VAR_environment"
value = "production"
}
}
A stack may have more labels than the selector. Every key and value in the selector must match.
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.