Skip to content

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).

when_modified:
autoapply: true

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

  1. Open a pull request with changes to your Terraform code.

  2. Terrateam automatically runs a Plan operation and comments on the pull request with the plan output.

  3. Review the plan output and collaborate with your team to ensure the changes are as expected.

  4. Once the pull request has been approved and all required checks have passed, merge the pull request.

  5. Terrateam detects the merge event and automatically triggers an Apply operation.

  6. 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:

dirs:
prod:
tags: [prod]
when_modified:
autoapply: true
staging:
tags: [staging]
when_modified:
autoapply: false

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:

hooks:
apply:
post:
- type: run
cmd: ['curl', '-X', 'POST', '--data', '{"text":"Changes have been applied!"}', '${SLACK_WEBHOOK_URL}']

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 to false in your Terrateam configuration file.
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 .