Managing Mergify with Terraform
How to manage Mergify configuration declaratively with the official Terraform provider.
The official Mergify Terraform provider lets you manage your Mergify configuration as code, alongside the rest of your infrastructure.
Prerequisites
Section titled Prerequisites-
The Mergify GitHub App is installed on your repositories.
-
A Mergify application key or a GitHub personal access token. See Authentication below.
Installation
Section titled InstallationDeclare the provider in your Terraform configuration:
terraform { required_providers { mergify = { source = "Mergifyio/mergify" version = "~> 0.1" } }}
provider "mergify" { # Token resolution order: # 1. the `token` attribute set here # 2. the MERGIFY_TOKEN environment variable # 3. the GITHUB_TOKEN environment variable}Then run:
terraform initAuthentication
Section titled AuthenticationThe provider authenticates against the Mergify API with a bearer token. Both Mergify application keys and GitHub personal access tokens are accepted.
Tokens are read from, in priority order:
- The
tokenattribute on theproviderblock. - The
MERGIFY_TOKENenvironment variable. - The
GITHUB_TOKENenvironment variable.
Resources
Section titled Resourcesmergify_repository_products
Section titled mergify_repository_productsManage which Mergify products are enabled on a single GitHub repository.
resource "mergify_repository_products" "monorepo" { owner = "Mergifyio" repository = "monorepo" products = ["merge_queue", "merge_protections", "ci_insights", "workflow_automation"]}The products attribute is declarative — applying the resource
sets the exact set of enabled products on the repository, removing any
that are not listed.
mergify_organization_default_products
Section titled mergify_organization_default_productsManage the default set of Mergify products enabled when a new repository of an organization is discovered by Mergify.
resource "mergify_organization_default_products" "defaults" { organization = "Mergifyio" products = ["merge_queue", "merge_protections"]}This only affects new repositories. Existing ones are managed via
mergify_repository_products.
Was this page helpful?
Thanks for your feedback!