Apply after Merge
Terrateam’s Auto-Apply-After-Merge functionality allows you to automatically apply changes to your infrastructure after a pull request has been merged. This can streamline your workflow and reduce the manual steps required to deploy your changes.
Enabling Auto-Apply-After-Merge
To enable Auto-Apply-After-Merge, you need to configure the when_modified.autoapply
setting in your Terrateam configuration file (.terrateam/config.yml
).
With when_modified.autoapply
is set to true
, Terrateam will automatically trigger an Apply operation after a pull request has been merged.
How It Works
-
Open a pull request with changes to your Terraform code.
-
Terrateam automatically runs a Plan operation and comments on the pull request with the plan output.
-
Review the plan output and collaborate with your team to ensure the changes are as expected.
-
Once the pull request has been approved and all required checks have passed, merge the pull request.
-
Terrateam detects the merge event and automatically triggers an Apply operation.
-
Terrateam comments on the merged pull request with the apply output, confirming that the changes have been applied.
Customizing Auto-Apply-After-Merge
Selective Auto-Apply
If you want to enable Auto-Apply-After-Merge only for specific directories or workspaces, you can use Dirs and Tags.
For example, you could have a configuration like this:
In this case, Auto-Apply-After-Merge will only be enabled for the prod
directory, while it will be disabled for the staging
directory.
Apply Requirements
Terrateam has a set of Apply Requirements that must be met before an Apply operation can be triggered, even with Auto-Apply-After-Merged enabled. These include:
- Requiring a certain number of approvals on the pull request
- Ensuring there are no merge conflicts
- Checking that all status checks have passed
You can configure these requirements in your Terrateam configuration file to ensure that changes are only applied when specific conditions are met.
Notifications
When an Auto-Apply-After-Merge operation is triggered, Terrateam will comment on the merged pull request with the apply output. You can also configure additional notifications, such as sending a message to a Slack channel or triggering a webhook, using Hooks.
For example, you could add a post-apply hook to send a Slack message:
Considerations
- Auto-Apply-After-Merge is a powerful feature that can automate your deployment process, but it’s important to ensure that your Terraform code is thoroughly reviewed and tested before merging.
- If an Auto-Apply-After-Merge operation fails, Terrateam will comment on the merged pull request with the error details. You may need to manually intervene to resolve the issue and apply the changes.
- Auto-Apply-After-Merge can be disabled at any time by setting
when_modified.autoapply
tofalse
in your Terrateam configuration file.