---
title: "Manage Grafana Assistant with Terraform | Grafana Cloud documentation"
description: "Manage Grafana Assistant resources as code with the Grafana Terraform provider."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

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

Expand table

| Resource         | Terraform reference                                                                                                                               |
|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| Rules            | [grafana\_assistant\_rule](https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/assistant_rule)                          |
| Skills           | [grafana\_assistant\_skill](https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/assistant_skill)                        |
| Quickstarts      | [grafana\_assistant\_quickstart](https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/assistant_quickstart)              |
| MCP servers      | [grafana\_assistant\_mcp\_server](https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/assistant_mcp_server)             |
| Terms acceptance | [grafana\_assistant\_terms\_acceptance](https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/assistant_terms_acceptance) |

## 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](/docs/grafana-cloud/platform/grafana-assistant/reference/http-apis/#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 ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```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](https://registry.terraform.io/providers/grafana/grafana/latest/docs).

## Create an Assistant rule

Add a rule to the configuration:

terraform ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```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](/docs/grafana-cloud/platform/grafana-assistant/reference/http-apis/rules) to create, read, update, and delete this resource.

Initialize the provider and review the proposed changes:

shell ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

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