Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
Set up Git Sync with Terraform
Caution
Git Sync is now GA for Grafana Cloud, OSS and Enterprise. Refer to Usage and performance limitations to understand usage limits for the different tiers.
Contact Grafana for support or to report any issues you encounter and help us improve this feature.
You can also configure Git Sync via the Grafana provisioning app platform using Terraform.
Before you begin
Before you begin, make sure to have the following:
- A Grafana Cloud account or an on-prem Grafana instance.
- Administrator permissions in your Grafana stack/instance.
- Terraform 1.11 or later installed on your machine. Refer to the Terraform install documentation to learn more.
Note
Save all of the following Terraform configuration files in the same directory.
Configure the Grafana provider
Use this Terraform configuration to set up the Grafana provider to provide the authentication required to configure Git Sync.
Create a service account and token in Grafana. For more information refer to Service account tokens or Creating and managing a Grafana Cloud stack using Terraform.
Make sure that the token has the Admin or the
Provisioning:Repositorieswriter permission.Create a file named
main.tfand add the following:terraform { required_providers { grafana = { source = "grafana/grafana" version = ">= 4.28.1" } } } provider "grafana" { cloud_api_url = "<STACK_URL>" stack_id = "<STACK_ID>" cloud_access_policy_token = "<SERVICE_ACCOUNT_TOKEN>" }
Replace the following field values:
STACK_URLwith the URL of your Grafana stack, for examplehttps://my-stack.grafana.net/<STACK_ID>with the Grafana stack ID, if you are using a Grafana Cloud stackSERVICE_ACCOUNT_TOKENwith the service account token that you created
Create the resources to use Git Sync
You need two resources for configure and manage Git Sync:
- The repository resource configures the Git repository to sync Grafana resources with. For examples, refer to Repository resource in the Terraform registry.
- The connection resource configures your Git provider credentials. For examples, refer to Connection resource in the Terraform registry.
For better understanding of the required resources, refer to Git Sync key concepts.


