Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/grafana-cloud/learn-and-build/as-code/terraform/cloud-products/terraform-frontend-observability.md, or by sending Accept: text/markdown to https://grafana.com/docs/grafana-cloud/learn-and-build/as-code/terraform/cloud-products/terraform-frontend-observability/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
Manage Frontend Observability in Grafana Cloud with Terraform
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 the Frontend Observability API, and how to use them to create a Frontend Observability app.
Note
The Grafana Terraform provider is updated frequently. For the latest provider version and the complete reference for every resource and data source, refer to the Grafana provider in the Terraform Registry.
Before you begin
Before you begin, ensure you have the following:
- A Grafana Cloud account, as shown in Get started
- Terraform installed on your machine
- Administrator permissions in your Grafana instance
Note
Save all the Terraform configuration files in the same directory.
Configure a provider for Grafana Cloud
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:write
Create a file named
cloud-provider.tfand add the following code block:terraformterraform { required_providers { grafana = { source = "grafana/grafana" version = ">= 3.22.1" } } } 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.net
Create an access policy and token for Frontend Observability
The Frontend Observability API needs its own access token. Create an access policy with the frontend-observability:read, frontend-observability:write, and frontend-observability:delete scopes using grafana_cloud_access_policy, and a token for it using grafana_cloud_access_policy_token.
Create a file named frontend-o11y-token.tf and add the following:
resource "grafana_cloud_access_policy" "frontend_o11y" {
provider = grafana.cloud
name = "frontend-o11y-policy"
region = data.grafana_cloud_stack.stack.region_slug
scopes = [
"frontend-observability:read",
"frontend-observability:write",
"frontend-observability:delete",
"stacks:read",
]
realm {
type = "stack"
identifier = data.grafana_cloud_stack.stack.id
}
}
resource "grafana_cloud_access_policy_token" "frontend_o11y" {
provider = grafana.cloud
name = "frontend-o11y-token"
region = grafana_cloud_access_policy.frontend_o11y.region
access_policy_id = grafana_cloud_access_policy.frontend_o11y.policy_id
}Configure the provider to use the Frontend Observability API
Add a second provider block that uses the token to connect to the Frontend Observability API. Add the following to cloud-provider.tf:
provider "grafana" {
alias = "frontend_o11y"
frontend_o11y_api_access_token = grafana_cloud_access_policy_token.frontend_o11y.token
}Create a Frontend Observability app
Use grafana_frontend_o11y_app to create an app in Frontend Observability.
Create a file named frontend-o11y-app.tf and add the following:
resource "grafana_frontend_o11y_app" "my_app" {
provider = grafana.frontend_o11y
stack_id = data.grafana_cloud_stack.stack.id
name = "<APP_NAME>"
allowed_origins = ["<ALLOWED_ORIGIN>"]
extra_log_attributes = {
team = "<TEAM_NAME>"
}
settings = {
"geolocation.enabled" = "1"
}
}
output "frontend_o11y_collector_endpoint" {
value = grafana_frontend_o11y_app.my_app.collector_endpoint
}Replace the following placeholders:
<APP_NAME>: The name of your frontend app.<ALLOWED_ORIGIN>: The origin that sends telemetry to Frontend Observability, for examplehttps://example.com.<TEAM_NAME>: A value for theteamattribute that’s added to every signal from the app.
The allowed_origins, extra_log_attributes, and settings arguments are required. For the available settings, refer to the grafana_frontend_o11y_app documentation.
After you run terraform apply, the frontend_o11y_collector_endpoint output shows the collector URL to use in the Faro Web SDK configuration of your app.
To bring an existing app under Terraform management, import it with its stack ID and name:
terraform import grafana_frontend_o11y_app.my_app "<STACK_ID>:<APP_NAME>"Replace the following placeholders:
<STACK_ID>: The ID of your Grafana Cloud stack.<APP_NAME>: The name of the existing Frontend Observability app.
Read an existing Frontend Observability app
To reference an existing Frontend Observability app without managing it in Terraform, use the grafana_frontend_o11y_app data source:
data "grafana_frontend_o11y_app" "existing" {
provider = grafana.frontend_o11y
stack_id = data.grafana_cloud_stack.stack.id
name = "<APP_NAME>"
}Summary
In this guide, you created an access policy and a token for Frontend Observability, and used them to create a Frontend Observability app with Terraform.
To learn more about managing Grafana Cloud using Terraform, refer to the Grafana provider documentation.
Was this page helpful?
Related resources from Grafana Labs


