docs/sources/as-code/infrastructure-as-code/terraform/terraform-frontend-observability.md
Learn how to use Terraform to manage Grafana Frontend Observability resources, such as your applications. This guide shows you how to create an access policy and a token for Frontend Observability so that you can connect to the Frontend Observability API.
Before you begin, ensure you have the following:
{{< admonition type="note" >}} All of the following Terraform configuration files should be saved in the same directory. {{< /admonition >}}
This Terraform configuration configures the Grafana provider to provide necessary authentication when interacting with the Cloud API.
The grafana_cloud_stack (Data Source) is used to retrieve the details of your instance.
Create a Grafana Cloud access policy and token. To create a new one, refer to Grafana Cloud Access Policies. Add your stack to the realms list. The scopes needed for the examples in this guide are:
accesspolicies:readaccesspolicies:writeaccesspolicies:deletedashboards:readdashboards:writedashboards:deleteorgs:readorgs:writestacks:readstacks:writestacks:deletestack-dashboards:readstack-dashboards:writestack-dashboards:deletestack-service-accounts:writeCreate a file named cloud-provider.tf and add the following code block:
terraform {
required_providers {
grafana = {
source = "grafana/grafana"
}
}
}
provider "grafana" {
alias = "cloud"
cloud_access_policy_token = "<CLOUD_ACCESS_POLICY_TOKEN>"
}
data "grafana_cloud_stack" "stack" {
provider = grafana.cloud
slug = "<STACK_SLUG>"
}
Replace the following field values:
<CLOUD_ACCESS_POLICY_TOKEN> with the access policy token you created in the first step<STACK_SLUG> with your stack slug, which is the subdomain where your Grafana Cloud instance is available: https://<STACK_SLUG>.grafana.netYou must create a Terraform configuration with the following:
frontend-observability:read, frontend-observability:write, and frontend-observability:delete scopes, using grafana_cloud_access_policy (Resource)frontend_o11y_api_access_token, using grafana_cloud_access_policy_token (Resource)After you have created the token, you can configure the provider as follows:
provider "grafana" {
frontend_o11y_api_access_token = "<access token from previous step>"
}
In this guide, you created an access policy and a token for Frontend Observability using Terraform.
To learn more about managing Grafana Cloud using Terraform, refer to the Grafana provider documentation.