capabilities.work

Plan a Run and Apply or Discard It

A 5-step recipe with Terraform. We can help you get access.

Recipe · 5 steps

Plan a Run and Apply or Discard It

with Terraform · IT Infrastructure Management

Queue a Terraform run, wait for the plan, and apply or discard it.

  1. Read the workspace to confirm it exists and is not locked, since a locked workspace will refuse to queue a new run.
  2. Queue a plan-only run against the workspace. Auto-apply is disabled on the run itself so this workflow stays in control of the confirmation decision.
  3. Poll the run until the plan settles, repeating while it is still pending, fetching, or planning, then branching on the terminal plan outcome.
  4. Confirm the finished plan and apply it, recording the supplied comment against the apply for the audit trail.
  5. Discard the run when the plan errored, so the workspace is not left holding a pending run that blocks the next one.
What you'll need to have ready
  • workspaceId: The workspace identifier to run against (e.g. ws-XXXXXXXXXXXX).
  • runMessage: The message recorded against the run, shown in the run history.
  • applyComment: The comment recorded when the plan is confirmed and applied.
  • discardComment: The comment recorded when a failed plan is discarded.
For your developer

Arazzo workflow terraform:plan-and-apply-run, 5 operations: GetWorkspace → CreateRun → GetRun → ApplyRun → DiscardRun. Specs on APIs.io.