For AI agents: the complete documentation index is available at /hclapi/llms.txt, the full documentation bundle is available at /hclapi/llms-full.txt, and this page is available as Markdown at /hclapi/docs/steps/transaction.md.

transaction

Groups multiple sql steps into one atomic transaction. A failure in any nested query rolls back the entire block.

Declaration

transaction "provision" {
  connection = connection.postgres.main

  sql "step_one" {
    # ...
  }

  sql "step_two" {
    # ...
  }
}

Attributes

AttributeTypeRequiredDescription
labelstringyesTransaction identifier
connectionconnectionyesPool used to acquire the transaction handle
sql blocksblockat least oneExecuted sequentially inside the transaction

Nested steps may reference each other's results in the normal way.

Rollback semantics

1. Query failure

A query error triggers an immediate ROLLBACK.

2. Caught constraint failure

A catch block that aborts with a status also rolls back and writes its error payload directly to the client.

3. Successful completion

If every statement succeeds, the engine issues COMMIT before continuing with the next pipeline step.

See Transactional writes for a complete example.