Apply Requirements and Overrides
Terrateam provides a set of apply requirements that must be met before an apply operation can be executed. These requirements help ensure that changes to your infrastructure are properly reviewed and approved before being applied. However, there may be situations where you need to override these requirements. Terrateam allows you to configure and manage apply requirements and overrides using access control.
Apply Requirements
Section titled “Apply Requirements”By default, Terrateam has the following apply requirements:
- The pull request must not have any merge conflicts.
- All status checks associated with the pull request must have passed.
Configuring Apply Requirements
Section titled “Configuring Apply Requirements”You can configure the apply requirements in your Terrateam configuration file (.terrateam/config.yml).
Here’s an example configuration:
apply_requirements: create_pending_apply_check: true checks: - tag_query: "" approved: enabled: true any_of: ["user:alice", "user:bob"] any_of_count: 1 all_of: [] merge_conflicts: enabled: true status_checks: enabled: true ignore_matching: - "ci/.*"In this example:
- The
approvedrequirement is enabled, and the pull request must have at least 1 approval from either the user “alice” or “bob”. - The
merge_conflictsrequirement is enabled, and the pull request must not have any merge conflicts. - The
status_checksrequirement is enabled, and all status checks associated with the pull request must have passed, except for those matching the regular expressionci/.*. You can also specify different apply requirements for different directories or workspaces using thetag_querykey. For example:
apply_requirements: checks: - tag_query: "dir:tf1" approved: enabled: true all_of: ["user:alice"] - tag_query: "dir:tf2" approved: enabled: true all_of: ["user:bob"]In this configuration, changes in the “tf1” directory require an approval from the user “alice”, while changes in the “tf2” directory require an approval from the user “bob”. By adjusting these settings, you can customize the apply requirements to match your team’s workflows and policies.
Access Control and Apply Overrides
Section titled “Access Control and Apply Overrides”Terrateam’s access control feature allows you to define a set of capabilities, such as plan and apply, and specify which users can perform those operations. This feature can be used to manage apply overrides and control who has the ability to bypass apply requirements.
Enabling Access Control
Section titled “Enabling Access Control”To enable access control, add the following to your Terrateam configuration file:
access_control: enabled: trueConfiguring Access Control Policies
Section titled “Configuring Access Control Policies”Access control policies define the capabilities and permissions for different users, groups, and roles. Here’s an example configuration:
access_control: enabled: true apply_require_all_dirspace_access: true plan_require_all_dirspace_access: false terrateam_config_update: ['*'] unlock: ['*'] policies: - tag_query: '' apply: ['role:maintain'] apply_autoapprove: ['user:alice'] apply_force: ['team:sre'] apply_with_superapproval: ['role:write'] plan: ['*'] superapproval: ['user:bob']In this example:
- The
applycapability is granted to users with themaintainrole in the repository. - The
apply_autoapprovecapability is granted to the useralice. - The
apply_forcecapability is granted to members of thesreteam. - The
apply_with_superapprovalcapability is granted to users with thewriterole in the repository, but only if a user with thesuperapprovalcapability has approved the pull request. - The
plancapability is granted to all users (*). - The
superapprovalcapability is granted to the userbob.
Using Apply Overrides
Section titled “Using Apply Overrides”With access control configured, users with the appropriate capabilities can override apply requirements using the following methods:
terrateam apply-force
Section titled “terrateam apply-force”Users with the apply_force capability can use this command to bypass all apply requirements and force an apply operation.
terrateam apply-autoapprove
Section titled “terrateam apply-autoapprove”Users with the apply_autoapprove capability can use this command to automatically approve and apply changes without requiring additional approvals.
Super Approval
Section titled “Super Approval”Users with the apply_with_superapproval capability can apply changes if a user with the superapproval capability has approved the pull request.
Best Practices
Section titled “Best Practices”When configuring and managing apply requirements and overrides with access control, consider the following best practices:
- Grant apply override capabilities only to trusted users or groups who understand the potential risks and consequences of bypassing apply requirements.
- Use the
apply_require_all_dirspace_accessandplan_require_all_dirspace_accesssettings to control whether users need access to all targeted directories (dirspaces) to perform apply or plan operations. - Use the
terrateam_config_updateandunlocksettings to control who can modify the Terrateam configuration and unlock locked resources. - Use the
tag_querykey in the apply requirements configuration to define granular requirements for different parts of your infrastructure, such as directories or workspaces. - Leverage the
any_of,any_of_count, andall_ofkeys in theapprovedsection to create flexible approval rules that match your team’s workflow and policies.