when_modified
The when_modified
configuration allows you to configure autoplan and autoapply operations based on pull request file changes. This enables you to automatically trigger plan and apply operations when specific files are modified in your repository.
Default Configuration
when_modified: file_patterns: ["**/*.tf", "**/*.tfvars"] autoplan: true autoplan_draft_pr: true autoapply: false
Keys
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 | Boolean | Automatically run a plan operation on a new pull request or an update on an existing one. Default is true. |
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 | Boolean | Automatically run an apply operation after merging a pull request. Default is false. |
File Patterns
The file_patterns
key specifies a list of file globs that identify changes in a directory. These patterns are relative to the root of the repository.
Auto-Plan
The autoplan
key enables or disables automatic plan operations on new pull requests or updates to existing ones.
Auto-Plan Draft Pull Request
The autoplan_draft_pr
key enables or disables automatic plan operations on new draft pull requests or updates to existing ones.
Auto-Apply
The autoapply
key enables or disables automatic apply operations after merging a pull request.
Examples
Auto-Plan on Terraform File Changes
when_modified: file_patterns: ["**/*.tf"] autoplan: true autoplan_draft_pr: false autoapply: false
This configuration triggers a plan operation automatically when any .tf
file in the repository is modified. It does not trigger plans on draft pull requests and does not automatically apply changes after merging.
Auto-Plan and Auto-Apply on Terraform and tfvars File Changes
when_modified: file_patterns: ["**/*.tf", "**/*.tfvars"] autoplan: true autoplan_draft_pr: true autoapply: true
This configuration triggers plan operations automatically on changes to .tf
or .tfvars
files, including draft pull requests. It also automatically applies changes after merging and creates a status check for pending applies.
Exclude Certain Files from Triggering Auto-Plan
when_modified: file_patterns: ["**/*.tf", "!**/modules/**/*.tf"] autoplan: true autoplan_draft_pr: true autoapply: false
This configuration triggers plan operations automatically on changes to .tf
files, including draft pull requests, but excludes .tf
files in the modules
directory and its subdirectories.