Skip to content

Stacks

A stack connects one Terraform or OpenTofu project to a managed lifecycle: a Git repository, branch and project root; the IaC engine and version; where the Terraform state lives; the configuration bundles and cloud integrations its runs receive; and the worker pool that executes them. Stacks live in a space.

Creating a stack, changing its details, engine, version or labels, and deleting it require the Admin role. Write users can trigger runs and change the stack's source, triggers, variables and bundle attachments. See Identity & Access.

Stack list

The Stacks page lists every stack with its Status (the most recent run's status, or No runs), Name, Space, Execution Target (Public or the private pool's name), IAC engine and Created date.

Each row's three-dot menu holds View Details, Add to favorites (or Remove from favorites, see Favorite stacks), Edit and Delete.

Creating a stack

Click Create Stack to open the four-step wizard.

Basic Info

  • Stack Name
  • Space: the space the stack belongs to. It cannot be changed later.
  • Worker Pool: Public Worker Pool, or one of your private pools. The picker warns when a private pool has no active workers or is inactive.

Git Config

  • Source type: VCS Integration (a connected provider; automated triggers where the provider delivers webhooks, see Triggers) or Raw Git URL (a public HTTPS repository; no automated triggers, runs start manually or through the API).
  • Integration, Repository and Branch. Only repositories enabled on the integration are offered.
  • Path (optional): the project root, the directory inside the repository where the tool runs. Leave it empty when the code is at the repository root. See how source is used in runs.
  • IaC Engine: OpenTofu (default) or Terraform, and the Version.
  • Terraform State: Zenfra-managed (default; Zenfra stores and locks state for you) or Customer-managed S3 (Your source declares an s3 backend; Zenfra never touches the state). This choice cannot be changed after creation. Read Terraform State before choosing Customer-managed S3.

Bundles

Optionally attach configuration bundles (in priority order) and Cloud Integrations, each with Read (for plan runs) and Write (for apply/destroy runs) permissions.

Review

Check the four cards, use Edit to go back, then Create Stack.

Stack detail

The header shows the stack's name and the status of its last run (Idle when there is none), the repository, branch, project root, engine and version, and the worker pool.

Trigger offers three run types:

Run type What it does
Plan & Apply Requires approval before applying. The standard deployment workflow: a tracked run plans, waits for your confirmation, then applies.
Plan Only Preview changes without applying.
Destroy Remove all managed resources.

If a run is already active, Zenfra asks Trigger Run While Active? before starting another one. The three-dot menu holds Add to favorites (or Remove from favorites), Watch stack (or Stop watching, see Watching a stack), Edit Stack and Delete Stack.

Tabs:

  • Runs: the stack's run history with a trigger-source filter. See Runs.
  • Resources: the inventory of resources this stack manages, indexed from its state; available for Zenfra-managed state. See Resources.
  • Configuration: a read-only view of the stack. The Source card shows Project root (working directory) (Repository root when unset) and, when push triggers are on, Also triggers on with the project globs, or Push globs (not in effect) when the stack has no project root because every push already triggers it.
  • Schedules: drift detection schedules for this stack. See Schedules and drift detection below.
  • Settings: Stack ID, Space, Worker Pool, Terraform State (read-only), Created and Last Run.

Watching a stack

Watch the stacks you want to hear about: choose Watch stack in the three-dot menu on the stack's page, and Stop watching to undo it. Watching and favoriting are separate: watching a stack does not add it to your favorites, and removing a favorite does not stop a watch.

Your watched stacks are saved with your account for the organization you are signed in to, so they follow you to any browser or device and are not shown to other members. You can watch up to 100 stacks per organization. A stack that is deleted drops out of every watch list. Watching and unwatching are not recorded in the audit log.

Which events on watched stacks email you is set under Notification settings. See Watching Stacks and Email Notifications for who gets each email and what it contains.

Editing a stack

Edit Stack opens a page with these sections. Each form has Reset and Save changes; bundle and cloud integration attachments are saved immediately.

  • Stack details: name and worker pool. The space cannot be changed after creation; to move a stack to a different space, delete and recreate it.
  • Source code: source type, integration, repository, branch and path, plus Automation Triggers: the Push Trigger switch and Project globs. See Triggers.
  • IAC configuration: engine and version.
  • Labels: the stack's labels.
  • Bundles: attach or detach bundles. Bundles that attach themselves through a label are listed under Attached by label and cannot be detached here; see Attaching by label.
  • Cloud integrations: attach an integration with Read or Write permission (Write includes read). Integrations attached through an auto-attach label appear as Auto-attached.
  • Danger zone: Delete this stack, confirmed by typing the stack's name. Deletion is a soft delete: the stack disappears from the list while its record and run history are kept for audit; its bundle and cloud integration attachments and its drift schedules are removed. It is not self-service reversible.

Labels

Labels are short lowercase tags on a stack, such as prod, team-payments or pci. Set them under Edit Stack > Labels: type a label and press Enter, then Save changes. With the Terraform provider, set labels on zenfra_stack.

  • A label is 1 to 63 characters: lowercase letters, digits, ., _ and -, starting with a letter or digit. Uppercase is refused, not converted.
  • A stack has at most 20 labels. Spaces around a label are trimmed and duplicates are dropped.

Labels do two things:

  • Attach bundles. A configuration bundle attaches itself to every stack that carries one of its auto-attach labels, within the bundle's space and the spaces that inherit its bundles. See Attaching by label.
  • Feed plan policies. A plan policy reads the labels as input.zenfra.stack.labels, so a rule can apply only to stacks labelled prod, or require that every stack has a team label.

A run keeps the labels the stack had when the run was created. Changing labels affects later runs only, and a policy re-evaluated on an existing run still sees that run's labels.

Runner image

A stack can name its own runner image: the container image its Terraform or OpenTofu commands and its hooks run in, instead of the image its worker is configured with. Use it when a stack needs a tool the default image lacks, such as Python for a scanner or a cloud CLI.

The setting is not in the stack editor yet. Set it with the API, with an API key that has the Admin role:

curl -X PUT -H "Authorization: Bearer zenfra_..." -H "Content-Type: application/json" \
  -d '{"runner_image": "ghcr.io/zenfracloud/zenfra-runner-opentofu@sha256:<digest>"}' \
  "https://api.zenfra.cloud/api/v1/stacks/<stack_id>"
  • The value is a repository pinned by digest: registry/repository@sha256: followed by 64 lowercase hexadecimal characters. A tag is refused, alone or next to a digest, so the image cannot change under the stack. A malformed value is refused with 400 and error code invalid_runner_image.
  • On the Public Worker Pool only the runner images Zenfra publishes are accepted: repositories whose name starts with ghcr.io/zenfracloud/zenfra-runner-, such as ghcr.io/zenfracloud/zenfra-runner-opentofu and ghcr.io/zenfracloud/zenfra-runner-terraform, each pinned by digest. Any other image is refused with 400 and error code runner_image_not_allowed, and so is moving a stack to the public pool while it names such an image, unless the same request clears it or replaces it with an image the public pool accepts.
  • On a private pool any digest-pinned image the worker's Docker can pull is accepted. The worker must run in Docker execution mode; see Runner image in the private worker guide for what the image must provide.
  • Leaving runner_image out of the request, or sending null, keeps the current value. "" clears it, and the stack's runs use the worker's own image again. GET /api/v1/stacks/<stack_id> returns the value as runner_image, absent when none is set.

A run keeps the requested pinned override the stack had when the run was created, immutable for this run: its apply after approval and a requeue from the dead-letter queue use the same image, even if the stack's setting changed or was cleared in between. Changing the setting affects later runs only.

The worker checks and pulls the image before the run's first command, so a run whose image cannot be used fails before any tool or hook runs: in Preparing, or in Applying for the apply after approval. These are the common causes, with the error code and the reason in the run log:

Error code Cause
RUNNER_IMAGE_UNAVAILABLE The worker's Docker could not pull the image: the digest does not exist, the registry is unreachable, or the worker has no credentials for it. Docker's own message is in the run log.
RUNNER_IMAGE_UNSUPPORTED The worker runs in host execution mode, which has no container to run the image in.

Dependencies

A stack can depend on other stacks: a successful apply of an upstream stack starts a separate run of this stack, which follows this stack's approval rules. The stack's Dependencies tab lists its upstream and downstream stacks. See Stack Dependencies.

Schedules and drift detection

A drift schedule periodically runs the stack to compare its configuration against the real infrastructure. Schedules live on the stack's Schedules tab under Drift detection. Creating, editing and deleting them requires the Admin role, and drift detection is available on the Starter plan and above: on the Free plan the tab shows Drift detection requires Starter plan, and plan changes go through support@zenfra.cloud. After a downgrade, existing schedules can still be viewed and deleted but no longer fire.

A schedule has:

  • Name.
  • Cron expression: 5-field cron (minute, hour, day of month, month, day of week), minimum cadence 15 minutes.
  • Timezone: an IANA name the cron fires in; defaults to UTC.
  • Enabled: switch it off to pause without deleting.
  • Reconcile (auto-apply): on, each fire creates a tracked run (Plan & Apply, so the changes still wait for approval); off, a plan-only proposed run.
  • Ignore state: off (the default), a fire is skipped while the stack holds a lock because a run is active; on, the schedule fires anyway and the run queues behind the active one.

The tab lists each schedule's Schedule, Timezone, Mode (Reconcile or Plan only, plus Ignore state), Next run and Status (Enabled or Paused; Plan required when the plan no longer includes drift detection).

When a drift run finds differences, the stack shows a Drift detected banner with the time of the last check and a link to that run, the affected resources carry a Drift signal in Resources, and the run appears with a Drift badge in the Runs tab.

With Reconcile on, the tracked run's plan is the check: when it finds changes and the run stops for approval, the stack already shows Drift detected, and applying the run clears it.

When drift checks fail

Every drift check is recorded on the stack, whether it succeeded or failed. A check succeeds when its plan completes: the drift run finishes, or with Reconcile on it reaches approval. It fails when the drift run fails before its plan completes, never starts on a worker, or its plan is denied by a policy. Cancelling a drift run before its plan completes records nothing. What happens after approval (the apply, or cancelling the run) is not part of the check, so the check recorded at approval stays.

GET /api/v1/stacks/<stack_id> returns:

Field Meaning
last_drift_check_at When the last drift check concluded, successful or not. Repeated failures keep it current.
last_drift_check_status succeeded or failed.
last_drift_check_run_id The drift run of that check.
drift_check_failures Drift checks failed in a row. Absent when there are none.
drift_check_failing_since When the current series of failed checks began. It stays put while checks keep failing and is removed by the next successful check.

has_drift, last_drift_detected_at, last_drift_delta and last_drift_run_id keep describing the last successful check; a failed check never changes them. Together the fields give four states:

  • Never checked: neither last_drift_check_at nor last_drift_detected_at is present.
  • Failing: drift_check_failures is above 0. Zenfra cannot tell whether the stack has drifted; last_drift_detected_at is when it last could.
  • Drift detected: not failing, and has_drift is true.
  • Clean: not failing, has_drift absent or false, and a check on record.

A stack whose last check happened before Zenfra recorded failed checks has only last_drift_detected_at; read it as the time of its last check.

A schedule that cannot create drift runs at all, for example because its fires are skipped while the stack is locked, records nothing and the failure count does not move. Compare last_drift_check_at with the schedule's cadence to notice a stack that has not been checked for too long.

Drift emails

Members who watch the stack and have Drift on a watched stack switched on in Notification settings (on by default) get an email about drift, whatever their role. Two events send one, each once per episode:

  • Drift detected: a drift check finds changes. No further email follows while the stack keeps showing Drift detected, however many checks find changes. The episode ends when a drift check finds no changes or a reconcile run is applied; drift found after that sends a new email. With Reconcile on, the run that stops for approval with changes is the check: watchers with the Write or Admin role also get its approval email, so they receive both.
  • Drift checks are failing: a drift check fails (see When drift checks fail). Further failures send nothing until a check succeeds; a check that fails after that sends a new email.

The email names the organization and the stack, says when the drift was detected or since when checks have been failing (in UTC), and links to the drift run it reports. A drift detected email gives the number of resources to add, change and destroy, and any imports, moves and forgets, as found by that run; a failing email says how many checks in a row had failed when Zenfra first saw the failure. It never contains plan output, resource addresses, error messages or log lines: open the run for those. The drift run's page shows the email line described in On the run page.

An email is attempted only while the drift, or the failing checks, are still present when Zenfra looks (about every 30 seconds) and again right before it is sent. Drift that clears before Zenfra sees it, or before the email goes out (for example a reconcile run approved and applied within moments), sends nothing, and processing delays can widen that window. A watch counts from the moment you add it: drift or failing checks that began before you started watching are reported from the next episode on. Drift, or failing checks, that were already present when Zenfra started sending these emails are not reported until they clear and come back. Delivery is at least once: an unconfirmed send is retried and may arrive twice, and delivery stops after five attempts or when the provider rejects the message.