When modified
The when_modified
directive in Terrateam allows you to match pull request file changes with autoplan and autoapply operations. This feature enables you to automatically trigger plans and applies based on specific file changes in your repository.
Configuration
When modified is configured in the .terrateam/config.yml
file under the when_modified
key. Here’s the default configuration:
File patterns
The file_patterns
key is used to specify a list of file globs that identify changes in a directory. These patterns are always relative to the root of the repository. You can prefix a file glob with !
to exclude it from the match.
Key | Type | Description |
---|---|---|
file_patterns | List | List of file globs to identify changes in a directory. Always relative to the root of the repository. Prefix with ! to exclude a file glob. Default is ["**/*.tf", "**/*.tfvars"] . |
Autoplan
The autoplan
key is used to enable or disable automatic plan operations on new pull requests or updates to existing ones.
Key | Type | Description |
---|---|---|
autoplan | Boolean | Automatically run a plan operation on a new pull request or an update on an existing one. Default is true . |
Autoplan draft pull request
The autoplan_draft_pr
key is used to enable or disable automatic plan operations on new draft pull requests or updates to existing ones.
Key | Type | Description |
---|---|---|
autoplan_draft_pr | Boolean | Automatically run a plan operation on a new draft pull request or an update on an existing one. Default is true . |
Autoapply
The autoapply
key is used to enable or disable automatic apply operations after merging a pull request.
Key | Type | Description |
---|---|---|
autoapply | Boolean | Automatically run an apply operation after merging a pull request. Default is false . |
Checks
The checks
key allows you to configure additional checks that must pass before an apply operation can be performed.
Approved
The approved
check requires that the pull request has received a certain number of approvals.
Key | Type | Description |
---|---|---|
enabled | Boolean | If the check is enabled. Default is false . |
count | Integer | Number of approvals needed to pass. Default is 1 . |
Merge conflicts
The merge_conflicts
check requires that the pull request has no merge conflicts.
Key | Type | Description |
---|---|---|
enabled | Boolean | If the check is enabled. Default is true . |
Status checks
The status_checks
check requires that all status checks associated with the pull request have passed.
Key | Type | Description |
---|---|---|
enabled | Boolean | If the check is enabled. Default is true . |
ignore_matching | List | List of regex to match against names of checks to ignore. Default is [] . |
Create pending apply check
The create_pending_apply_check
key is used to enable or disable the creation of status checks for pending applies.
Key | Type | Description |
---|---|---|
create_pending_apply_check | Boolean | Create status checks for pending applies. Default is true . |
Examples
Autoplan on Terraform file changes
This configuration will automatically trigger a plan operation when any .tf
file in the repository is modified. It will not trigger plans on draft pull requests and will not automatically apply changes after merging.
Autoapply with approval check
This configuration will automatically trigger plan operations on any changes to .tf
or .tfvars
files, including draft pull requests. It will also automatically apply changes after merging, but only if the following conditions are met:
- The pull request has received at least 2 approvals.
- The pull request has no merge conflicts.
- All status checks associated with the pull request have passed, except for those matching the regex
ci/.*
. Additionally, it will create a status check for pending applies.
Exclude certain files from triggering autoplan
This configuration will automatically trigger plan operations on any changes to .tf
files, including draft pull requests, but will exclude any .tf
files in the modules
directory and its subdirectories.