Skip to content

Actions Reference — Declaring

How to declare an action and bind it to a resource’s lifecycle: action blocks, triggers in a resource or in a *.turf.hcl overlay, on_failure, condition, and what an action’s configuration can read. Answering a turf action when the apply stops for it is deployment: skill_deployment → references/turf-actions.md.

An action is an operation that writes no resource state — power-cycle a host, empty a bucket, run a post-deploy job. A provider’s actions are described like its resources: provider_describe({ action_type: "aws_lambda_invoke" }).

A turf_action is the action you perform yourself during the apply: its provider is the engine’s built-in terraform.io/builtin/turf, implied by the turf_ prefix, so there is nothing to declare or install.

action "turf_action" "verify_web" {
config {
prompt = "Verify the web container serves: GET inputs.url and expect 200 with \"Welcome to nginx\". Fail if it does not."
inputs = {
container_id = caller.id
url = "http://localhost:${caller.ports[0].external}/"
}
}
}
Field Required Meaning
prompt yes What to do, and what counts as failure. A decision for the user is a prompt that says to ask them.
inputs no Any value — IDs, endpoints, names — evaluated like any action config, caller included, sent as JSON. Nothing sensitive (wrap a value in nonsensitive() to show it on purpose); at most 64 KiB.
non_interactive no fail (default) or skip: the answer only where no agent is in the loop (the engine’s own command line, unattended).

In the resource, in native Terraform syntax — respect it where the user wrote it:

resource "terraform_data" "release" {
input = var.version
lifecycle {
action_trigger {
events = [after_create, after_update]
actions = [action.turf_action.verify_web]
on_failure = halt
}
}
}

In an overlay — Turf’s extension, and the way to add an interaction point without changing the user’s Terraform. A *.turf.hcl file in the configuration directory holds action blocks and top-level action_trigger blocks naming a target. tofu and terraform ignore the file by its name; the engine lays it over the configuration at every plan. Tell the user which file you wrote: it is theirs.

gates.turf.hcl
action "turf_action" "gate" {
config {
prompt = "Ask the user whether to create the database now; fail with their reason if they decline."
}
}
action_trigger "gate" {
target = module.db.aws_db_instance.main
events = [before_create]
actions = [action.turf_action.gate]
on_failure = halt
}
  • target is a managed resource of the overlay’s own module or any module beneath it, by path: module.db.aws_db_instance.main, module.net.module.vpc.aws_vpc.this. A registry or git module’s resource is reached this way, since its directory is not yours to write in (a package module’s own overlays are ignored, with a warning). Name the module with no instance key: the trigger binds every instance of a counted or for_each call, and module.db["a"] is refused. A target in a module the overlay’s module does not declare is refused.
  • The actions and the condition are the overlay’s own module’s — its actions, variables and locals — and caller is the target instance. An action that reads the module it is bound into (module.db.endpoint while bound to module.db.aws_db_instance.main) is refused as a cycle: read caller instead.
  • On one resource, a module’s own triggers run before those of the modules above it, and within one module in the order they are written.
  • The address-targeted action_trigger is overlay-only: in a .tf file it is refused.
  • turf_action needs no init. Re-run init when an overlay’s action needs a provider not yet installed.

In memory, for one convergence. The same file can ride a plan command instead of the directory: up({ overlays: { "postcheck.turf.hcl": "<action and action_trigger blocks>" } }) — any plan command takes overlays. Its triggers bind in every round of that convergence and nothing is written; a later up without it drops it; a name that collides with a real file is refused. Use it for a check wanted once, around this rollout. init does not report it.

Events: before_create, after_create, before_update, after_update, before_destroy, after_destroy. A before_* step gates the change: it waits on the action. An after_* step follows it.

on_failure — what a failed action does to the change it is bound to:

on_failure In a plan made by up (and the other forward commands) In a destroy
halt (default) Fails the round: on a before_* event the change never runs; what waits on it is skipped. A warning; the teardown goes on.
continue A warning; the apply goes on. A warning.
taint On after_create: taints the new object, so the next plan replaces it, and halts what waits on it. On any other event it acts as halt. A warning.

The request the agent receives carries the effective policy (on_failure) and says it in words (if_failed). As in Terraform, a before_destroy gate cannot stop a destroy: only the user’s approval of the plan can.

condition gates the trigger on an expression known at plan time; false skips the action. A condition on a trigger with a destroy event is refused.

An entry in actions may name each instance’s own action: actions = [action.local_command.cordon[each.key]] on a for_each resource, or [count.index] on a counted one. The key is the calling instance’s — in an overlay trigger, the target instance’s. A key of the wrong type is a plan error for that instance, and a key the action does not have is “Reference to non-existent action instance”. An orphan whose key left the action warns and invokes none of its actions.

Syntax gotcha — bare tokens, not strings

Section titled “Syntax gotcha — bare tokens, not strings”
  • events are bare identifiers: events = [before_create]. ["before_create"] fails “Invalid action_trigger event”.
  • actions are bare references: actions = [action.turf_action.gate]. ["action.turf_action.gate"] is a list of one string.
  • on_failure is a bare keyword: halt, continue or taint. "halt" is rejected.

An action’s config {} — prompt and inputs alike — may interpolate ${…} expressions. What they resolve against depends on the event (Terraform 1.16 semantics):

  • caller is the triggering resource:
    • before_create / before_update → its planned value. A computed attribute (caller.id on a resource that does not set id) is not known yet, and the action fails without being asked: read what the configuration sets (caller.input), or move the step to an after_* event.
    • after_create / after_update → the applied value.
    • before_destroy / after_destroy → the prior value, what is being destroyed.
    • caller does not exist in a direct invoke.
  • Destroy-event configs freeze at plan: every expression is resolved when the plan is made, against the world before the teardown. Anything unresolvable at plan fails the plan.
  • Create- and update-event configs are reference-checked at plan (a typo fails the plan, naming the reference) and re-resolved at invoke, so a reference to a resource created earlier in the round resolves to its real value.
  • A before_* config must not reference its triggering resource by address — that is an ordering cycle, and the plan says so: use caller.
  • A config that cannot be resolved, holds a sensitive value, or has inputs past the bound fails the action without asking; on_failure applies as for any failure.

A notification — a tool call; a failed notice only warns:

action "turf_action" "announce" {
config {
prompt = "Tell the team web ${caller.output.version} is live at ${caller.output.url}: post one line to the release channel with your messaging tool. If you have none, fail and say so."
inputs = { version = caller.output.version, url = caller.output.url }
}
}
action_trigger "announce" {
target = terraform_data.release
events = [after_create, after_update]
actions = [action.turf_action.announce]
on_failure = continue
}

A conversation before proceeding — the update waits on the user’s answer:

action "turf_action" "handoff" {
config {
# Before an update caller is the PLANNED value: read what the configuration sets.
prompt = "Before web moves to ${caller.input.version}: show the user what changes, ask whether support has been told. Succeed only if they say go ahead, quoting them; if they decline, fail with their reason."
inputs = { to_version = caller.input.version }
}
}
action_trigger "handoff" {
target = terraform_data.release
events = [before_update]
actions = [action.turf_action.handoff]
}

Verify after a create — after_create with on_failure = taint: a failed check taints the new object and the next up replaces it. On any other event, use halt.

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