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.

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.

KeyTypeDescription
enabledBooleanIf the check is enabled. Default is false.
countIntegerNumber of approvals needed to pass. Default is 1.

Merge conflicts

The merge_conflicts check requires that the pull request has no merge conflicts.

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

KeyTypeDescription
enabledBooleanIf the check is enabled. Default is true.
ignore_matchingListList 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.

KeyTypeDescription
create_pending_apply_checkBooleanCreate status checks for pending applies. Default is true.

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.

Autoapply with approval check

when_modified:
file_patterns: ["**/*.tf", "**/*.tfvars"]
autoplan: true
autoplan_draft_pr: true
autoapply: true
checks:
approved:
enabled: true
count: 2
merge_conflicts:
enabled: true
status_checks:
enabled: true
ignore_matching: ["ci/.*"]
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, 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

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 .