Skip to content
GantryCD

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:

  1. Auto-attached contexts. A higher auto_attach_priority wins between them.
  2. Directly attached contexts. A later ID in context_ids wins.
  3. 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.