Script Run
Note
This is an experimental feature that might be subject to change in the future. To use it now, you must enable the project config option terramate.config.experiments = ["scripts"]
Overview
A script is a collection of different commands which are part of a workflow. You can run a single script run
command to run all the commands of the script block as one single executable unit without having to run them one by one.
Usage
terramate script run [options] CMD...
CMD
needs to match the label defined in the script block. For example:
script "mycommand" {
...
}
The above script can be run with script run mycommand
.
Scripts follow the same inheritance rules as globals and will only run where:
- The script is defined or inherited.
- The specified filters (
--changed
,--tags
, etc.) match.
Options
--changed
Runs the script on stacks with changes.--tags=tags
Runs the script on stacks with specific tags.--disable-change-detection=mode
Disables change detection for uncommitted files or other modes.--continue-on-error
Continues executing the script even if errors occur.--dry-run
Shows what would happen without executing the script.--no-recursive
Runs the script only in the current stack without traversing subdirectories.--status=status
Filters stacks based on Terramate Cloud status (e.g.,unhealthy
).--reverse
Runs the script in reverse order across stacks.
Examples
Run a script called deploy
on all stacks where it is available:
terramate script run deploy
Run the deploy
script on all changed stacks:
terramate script run --changed deploy
Run the deploy
script on all changed stacks, ignoring uncommitted files:
terramate script run --changed --disable-change-detection=git-uncommitted deploy
Run the deploy
script on all changed stacks and continue on error:
terramate script run --changed --continue-on-error deploy
Perform a dry run of the deploy
script:
terramate script run --dry-run deploy
Run the deploy
script in a specific stack without recursing into subdirectories:
terramate -C path/to/stack script run --no-recursive deploy
Run a script in all stacks with a specific Terramate Cloud status (unhealthy
):
terramate script run --status=unhealthy deploy
Run the destroy
script on all stacks in reverse order:
terramate script run --reverse destroy