• Docs
  • Common Use Cases
  • Custom Workflows
  • Executing Custom Commands

Custom Commands

Run a custom command during a Terrateam operation:

  • Pre workflow: one time per operation
  • Post workflow: one time per operation
  • Part of a workflow: one time per workflow in an operation

Hooks are executed a single time pre and post a Plan or Apply operation. Workflows can replace the default workflow steps Terrateam executes during an operation.

Order of operations:

  1. Pre hooks executed a single time.
  2. Workflow steps for all targeted Dirspaces.
  3. Post hooks executed a single time.

In the following example:

  • Echo statements are written to the console pre and post Plan and Apply operations.
  • Environment variables are echoed to the console using the cmd parameter for Plan and Apply workflow steps that run against each targeted Dirspace in the operation.
  • $TERRATEAM_DIR: Current working directory for the Dirspace.
  • $TERRATEAM_WORKSPACE: Workspace that is currently being executed against the Dirspace.
hooks:
  plan:
    pre:
      - type: run
        cmd: ['echo', 'pre-plan-hook']
    post:
      - type: run
        cmd: ['echo', 'post-plan-hook']
  apply:
    pre:
      - type: run
        cmd: ['echo', 'pre-apply-hook']
    post:
      - type: run
        cmd: ['echo', 'post-apply-hook']
workflows:
  - tag_query: ""
    plan:
      - type: init
      - type: run
        cmd: ['echo', 'pre-plan-workflow', '$TERRATEAM_DIR', '$TERRATEAM_WORKSPACE']
      - type: plan
      - type: run
        cmd: ['echo', 'post-plan-workflow', '$TERRATEAM_DIR', '$TERRATEAM_WORKSPACE']
    apply:
      - type: init
      - type: run
        cmd: ['echo', 'pre-apply-workflow', '$TERRATEAM_DIR', '$TERRATEAM_WORKSPACE']
      - type: apply
      - type: run
        cmd: ['echo', 'post-apply-workflow', '$TERRATEAM_DIR', '$TERRATEAM_WORKSPACE']