Grafana Cloud

Manage Grafana Assistant with Terraform

Use the Grafana Terraform provider to define Assistant resources in configuration files and manage their lifecycle with Terraform. This lets you review configuration changes in version control and apply them consistently across stacks.

Choose a resource

The Grafana provider includes these Assistant resources. Follow each link for its arguments, examples, and import instructions.

Before you begin

You need Terraform installed, a Grafana Cloud stack with Assistant enabled, and a Grafana service account token. Grant the service account access to the Assistant app and the permissions for the resources it manages. Refer to HTTP API requirements and the permissions on the corresponding resource page.

For user-scoped resources, the service account is the owner, not the person who created its token. Use scope = "tenant" for resources shared across the organization.

Configure the provider

Set GRAFANA_URL to your Grafana Cloud stack URL and GRAFANA_AUTH to your service account token. Use the stack URL, for example https://your-stack.grafana.net, rather than the HTTP API base path.

Create a Terraform configuration file:

terraform
terraform {
  required_providers {
    grafana = {
      source  = "grafana/grafana"
      version = "~> 4.46"
    }
  }
}

provider "grafana" {}

The provider reads the URL and token from those environment variables. For other configuration options, refer to the Grafana provider documentation.

Create an Assistant rule

Add a rule to the configuration:

terraform
resource "grafana_assistant_rule" "service_health" {
  name         = "Service health summaries"
  rule_content = "Include request rate, error rate, and duration when summarizing service health."
  scope        = "tenant"
  applications = ["assistant"]
}

The service account needs the tenant rule permissions listed in the Rules API to create, read, update, and delete this resource.

Initialize the provider and review the proposed changes:

shell
terraform init
terraform plan

Run terraform apply when you are ready to create the rule.

Manage existing resources

To bring an existing Assistant resource under Terraform management, use the import instructions in its provider reference. Keep subsequent changes in the Terraform configuration: edits through the Assistant UI or HTTP API can differ from that configuration and may be overwritten by a later Terraform apply.