Skip to content

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:

when_modified:
file_patterns: ["**/*.tf", "**/*.tfvars"]
autoplan: true
autoplan_draft_pr: true
autoapply: false

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.

KeyTypeDescription
file_patternsListList 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.

KeyTypeDescription
autoplanBooleanAutomatically 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.

KeyTypeDescription
autoplan_draft_prBooleanAutomatically 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.

KeyTypeDescription
autoapplyBooleanAutomatically run an apply operation after merging a pull request. Default is false.

Examples

Autoplan on Terraform file changes

when_modified:
file_patterns: ["**/*.tf"]
autoplan: true
autoplan_draft_pr: false
autoapply: false

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.

Autoplan and autoapply on Terraform and tfvars file changes

when_modified:
file_patterns: ["**/*.tf", "**/*.tfvars"]
autoplan: true
autoplan_draft_pr: true
autoapply: true
create_pending_apply_check: true

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. Additionally, it will create a status check for pending applies.

Exclude certain files from triggering autoplan

when_modified:
file_patterns: ["**/*.tf", "!**/modules/**/*.tf"]
autoplan: true
autoplan_draft_pr: true
autoapply: false

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.

We use cookies and similar technologies to provide certain features, enhance the user experience and deliver content that is relevant to your interests. Depending on their purpose, analysis and marketing cookies may be used in addition to technically necessary cookies. By clicking on "Agree and continue", you declare your consent to the use of the aforementioned cookies. Here you can make detailed settings or revoke your consent (in part if necessary) with effect for the future. For further information, please refer to our Privacy Policy .