Skip to main content

Hooks

The hooks directive can be used to run commands or set environment variables pre and post workflows.

info

Pre and post hooks are only executed a single time during a Terrateam run

Pre Hooks ---> Workflow 1, Workflow 2, ... Workflow N ---> Post Hooks

💡 Commands are executed from the repository checkout directory $TERRATEAM_ROOT

Keys

Plan

KeyTypeDescription
prearrayCommands to run before a plan workflow
postarrayCommands to run after a plan workflow

Apply

KeyTypeDescription
prearrayCommands to run before an apply workflow
postarrayCommands to run after an apply workflow

Parameters

env

ParameterTypeDescription
namestringName of environment variable
cmdarrayCommand to use to set environment variable
trim_trailing_newlinesboolTrim trailing newlines. Default is true.

run

KeyTypeDescription
cmdarrayCommand to run
run_onstringWhat situation to run the command on. Possible values: always, success, failure. Default: success.
capture_outputstringWhen capture_output is set to true, command output is included in the GitHub pull request comment on a failure. Sensitive data is not masked. Be aware, this data is sent back to the Terrateam backend for processing. Default is false.

Default Configuration

hooks:
plan:
pre: []
post: []
apply:
pre: []
post: []

Example

  • Set the TF_LOG environment variable to DEBUG before running all workflows
  • Run echo statements after running all workflows
hooks:
plan:
pre:
- type: env
name: TF_LOG
cmd: ['echo', 'DEBUG']
post:
- type: run
cmd: ['echo', 'post-plan-hook']
apply:
pre:
- type: env
name: TF_LOG
cmd: ['echo', 'DEBUG']
post:
- type: run
cmd: ['echo', 'post-apply-hook']
- type: run
run_on: failure
cmd: ['notify-failed-apply']