Skip to content

Journey: Deploying with guardrails

Three guardrails, in the order they bite. Every provider binary is scanned before it executes. The workload you deploy is pinned to a commit, so what runs is what was reviewed. Every plan is checked against policy before it is approved — and two of those three ride with the configuration as steps of the apply, so a run that skips the approval pause cannot skip them.

Example: use-cases/guardrails in turf-examples — a kind cluster and podinfo in it, the module pinned to a commit of the examples repository. Load skill_deployment. One beat at a time; end each on a cue.

What it needs: a scanner (trivy or grype on the PATH, or the Grype MCP server), a policy engine (opa or conftest on the PATH, or the OPA MCP server), Docker for the kind cluster, and git on the engine’s PATH for the pinned module. With no scanner, say so and narrate beat 2 from the init result; with no policy engine, read the plan document and apply the one rule by hand, and say that is what you did.


Beat 1 — What the guardrails are (start here, tool-free)

Section titled “Beat 1 — What the guardrails are (start here, tool-free)”

Name the three and show the files. main.tf:

resource "kind_cluster" "demo" { name = var.cluster_name node_image = var.node_image wait_for_ready = true }
resource "random_pet" "name" { length = var.length } # default 1 — the policy violation, on purpose
module "app" {
source = "git::https://github.com/turfbuild/turf-examples.git//terraform/modules/podinfo?ref=<commit>"
name = "podinfo-${random_pet.name.id}"
cluster_endpoint = kind_cluster.demo.endpoint
}

policies/readable_pet_names.rego — package terraform, a deny set, one rule: a random_pet with length < 2 is denied. And guardrails.turf.hcl:

action "turf_action" "attest" { config { prompt = "Attest the provider scan: every provider init installed was scanned in this session, by package directory, and none was blocked…" } }
action "turf_action" "check" { config { prompt = "Evaluate policies/*.rego against this plan… fail on any deny, quoting it." inputs = { address = "random_pet.name", length = caller.length } } }
action_trigger "guardrails" {
target = random_pet.name # the app is named after it, so the app waits on it
events = [before_create]
actions = [action.turf_action.attest, action.turf_action.check]
on_failure = halt # a failure stops the pet and the app; the cluster still applies
}

Check the tools. Your cue — “install the providers.”


  • init({ path: "<examples>/use-cases/guardrails", config_alias: "guard" }).

providers[] has tehcyx/kind, hashicorp/helm and hashicorp/random, each with its version, its package_dir — the real directory in the plugin cache — and its hashes; lock_file says .terraform.lock.hcl was created. init installs and reports; it does not scan. You do, now, before open, because nothing has executed a provider yet:

  • For each package_dir: trivy rootfs --scanners vuln,secret <package_dir> (or grype dir:<package_dir>, or the Grype MCP server’s directory scan). Present one line per provider: version, findings by severity, verdict.
  • A CRITICAL finding, or anything the user’s policy blocks, means stop here: say which provider, and that the session ends before the workspace opens — the binary never ran. (Expect the stock providers to pass; say what you found honestly.)

One line on the lock file: the hashes init recorded are what every later plan verifies; a provider whose package no longer matches is refused as an inconsistent lock.

Your cue — “what about the module?”


Point at the source: a git:: URL with a ref. init fetched that commit of terraform/modules/podinfo and nothing else — the module is in the data_dir init reported (.terraform/modules), read it if the user wants. An upgrade is the ref bumped and init({ config_alias: "guard", upgrade: true }); the next plan is the diff. oci:// module sources behave the same way (anonymous pulls). The configuration directory itself is still local; say so if asked — a remote root is not something Turf does today.

Your cue — “plan it.”


  • open({ config_alias: "guard", workspace_alias: "guard" }).
  • up({ workspace_alias: "guard" }) — the default length = 1. The plan: the cluster and the pet to add, podinfo deferred (provider_config_unknown), plan.invocations with attest and check on random_pet.name.
  • Evaluate the plan before approving: write show’s document to a file and run opa eval -i <file> -d <example>/policies 'data.terraform.deny' (or conftest test <file> -p <example>/policies, or the OPA MCP server with the document as input.tfplan). One denial: random_pet.name: length should be >= 2. Do not apply. cancel({ workspace_alias: "guard" }). Report the reason.
  • up({ workspace_alias: "guard", var: { length: 2 } }); evaluate again → no denials. Approve by the digest of the plan that was checked — say why: the plan waits at its approval point and nothing applies until that digest is named, so the policy tool read the plan about to be approved; a plan that changed since is refused.

Your cue — “apply it.”


apply({ convergence_id, plan_digest }). Before the first create the call returns awaiting_actions for attest: answer from the scan in beat 2 (one progress line per provider, its verdict). The apply goes on and stops again for check — two steps on one caller come one pause each, in the order written: answer from the policy run in beat 4, or run it again on inputs (length = 2): “no denials”. Make the point: these steps are the configuration’s, so a run the agent approves itself stops for them too — an apply-time step the author wrote in, not a second approval. The cluster comes up (round 1), the engine plans round 2 on its own: podinfo, now concrete. Approve; apply; converged. output release.

Offer teardown — destroy({ workspace_alias: "guard" }), approve, apply — then close({ workspace_alias: "guard" }).

Your cue — “through my TACO?” or “wrap it up.”


Triggered by: the user coming from the TACO journey, or asking.

The same check with the policy read from the control plane: with the TACO’s MCP server, read the policy group that governs the workspace’s environment, fetch each policy’s rego from the repository it points at (the Scalr example’s policies/), evaluate show’s document locally, and gate on each policy’s enforcement level — hard-mandatory blocks, advisory warns. The TACO never ran a plan; governance composed at the approval point, the way beat 4 did. For provider actions and lifecycle triggers in depth, read skill_authoring → references/actions.md.

Turf™ is a trademark of Turf LLC. Terraform® is a trademark of HashiCorp. Ansible® is a trademark of Red Hat, LLC, registered in the United States and other countries. Helm®, Kubernetes®, Prometheus® and OpenTelemetry® are registered trademarks, and Jaeger™ is a trademark, of the Linux Foundation. OpenTofu® and Model Context Protocol® are registered trademarks of LF Projects, LLC. All other trademarks are the property of their respective owners. Turf is not affiliated with, endorsed by, or sponsored by HashiCorp, IBM, Red Hat, the Linux Foundation, LF Projects or the OpenTofu project.

© 2026 Turf LLC. Free for individuals, education and small businesses within the Community limits, under the Turf Community Edition License 1.0. Government and larger organizations need a commerciallicense.turf.build · Discord ·GitHub