terraform-provider-stackgen

sg_workflow (Resource)

⚠️ Experimental — This resource is part of the Guild platform and may change in future releases.

Manages a workflow — a unified playbook that combines stage definitions, agent bindings, triggers, and governance references into a single draft resource.

Set approve to true to promote draft or deprecated versions to approved after apply (Guild only allows one approved version per workflow; approving deprecates the previously approved one).

Create-time 409 adoption after a successful read is controlled by the provider attribute adopt_on_conflict (default true).

Example Usage

# When to use: Multi-stage agent playbook (RCA, remediation, audits). Prefer a
# workflow over a single agent when you need ordered stages, runbook refs,
# evidence checklists, or event-driven triggers.
#
# Prerequisites: agents referenced in stage_bindings (or create them in the same
# stack). Set approve = true so drafts are not left pending in the UI.
#
# Related: sg_agent, sg_runbook_sop (runbook_refs), sg_evidence_checklist,
# sg_remediation_pattern, sg_webhook / sg_agent_schedule (triggers),
# sg_action_type (custom stage actions).
#
# See also: resource_with_triggers.tf and examples/workflow/main.tf.
resource "sg_workflow" "example" {
  name    = "example-triage"
  domain  = "incident-response"
  approve = true

  stages {
    stage_id    = "triage"
    description = "Initial classification and routing."
    required    = true
  }
}
# When to use: Event-matched workflow (PagerDuty/Datadog-style ingress). Pair
# with sg_webhook (HTTP) or an app-managed ingest path. Bind each stage to an
# agent_ref; optional runbook_refs point at sg_runbook_sop names.
#
# stages / stage_bindings: stage_id must match between the stage definition and
# its binding. Keep stage_ids stable — renaming forces rebinding.
resource "sg_agent" "lead" {
  name = "workflow-lead"
}

resource "sg_workflow" "event_driven" {
  name        = "pagerduty-bridge"
  domain      = "incident-response"
  description = "Matches incoming PagerDuty-style events."
  approve     = true

  # Optional: link SOPs / evidence for the whole playbook.
  # runbook_refs             = ["database-failover"]
  # evidence_checklist_ref   = "post-incident-review"

  triggers {
    field  = "source"
    values = ["pagerduty"]
    type   = "active"
    source = "pagerduty"
  }

  stages {
    stage_id = "ack"
    required = true
  }

  stage_bindings {
    stage_id  = "ack"
    agent_ref = sg_agent.lead.name
    note      = "Acknowledge and summarize the incident."
  }
}

Import

Import an existing sg_workflow using its workflow name or UUID:

terraform import sg_workflow.example 'incident-triage'

A workflow UUID can also be used; the provider resolves it to the unique workflow name via ListWorkflows (there is still no Guild get-by-UUID API).

terraform import sg_workflow.example '11111111-1111-1111-1111-111111111111'

Operational notes

Import accepts a workflow name or UUID. UUID import resolves the name via paginated ListWorkflows (Guild still has no get-by-UUID API); state stores the name for later reads.

Schema

Required

Optional

Read-Only

Nested Schema for metadata

Optional:

Nested Schema for metadata.tool_middleware

Optional:

Nested Schema for metadata.tool_middleware.circuit_breaker

Optional:

Nested Schema for metadata.tool_middleware.concurrency

Optional:

Nested Schema for stage_bindings

Optional:

Nested Schema for stage_bindings.spawn_contracts

Required:

Optional:

Nested Schema for stages

Required:

Optional:

Nested Schema for triggers

Optional: