Skip to content

Apply after merge

Terrateam’s autoapply 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 autoapply after merge

To enable autoapply after merge, you need to configure the autoapply setting in your Terrateam configuration file (.terrateam/config.yml).

when_modified:
autoapply: true

With autoapply 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 autoapply after merge

Selective autoapply

If you want to enable autoapply 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, autoapply 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 autoapply 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 autoapply 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

  • Autoapply 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 autoapply 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.
  • Autoapply after merge can be disabled at any time by setting 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 .