Sets up Synthetic Monitoring on a Grafana cloud stack and generates a token. Once a Grafana Cloud stack is created, a user can either use this resource or go into the UI to install synthetic monitoring. This resource cannot be imported but it can be used on an existing Synthetic Monitoring installation without issues.
Note that this resource must be used on a provider configured with Grafana Cloud credentials.
Required access policy scopes:
variable "cloud_access_policy_token" {
description = "Cloud Access Policy token for Grafana Cloud with the following scopes: accesspolicies:read|write|delete, stacks:read|write|delete"
}
variable "stack_slug" {}
variable "cloud_region" {
default = "us"
}
// Step 1: Create a stack
provider "grafana" {
alias = "cloud"
cloud_access_policy_token = var.cloud_access_policy_token
}
resource "grafana_cloud_stack" "sm_stack" {
provider = grafana.cloud
name = var.stack_slug
slug = var.stack_slug
region_slug = var.cloud_region
}
// Step 2: Install Synthetic Monitoring on the stack
resource "grafana_cloud_access_policy" "sm_metrics_publish" {
provider = grafana.cloud
region = var.cloud_region
name = "metric-publisher-for-sm"
scopes = ["metrics:write", "stacks:read"]
realm {
type = "stack"
identifier = grafana_cloud_stack.sm_stack.id
}
}
resource "grafana_cloud_access_policy_token" "sm_metrics_publish" {
provider = grafana.cloud
region = var.cloud_region
access_policy_id = grafana_cloud_access_policy.sm_metrics_publish.policy_id
name = "metric-publisher-for-sm"
}
resource "grafana_synthetic_monitoring_installation" "sm_stack" {
provider = grafana.cloud
stack_id = grafana_cloud_stack.sm_stack.id
metrics_publisher_key = grafana_cloud_access_policy_token.sm_metrics_publish.token
}
// Step 3: Interact with Synthetic Monitoring
provider "grafana" {
alias = "sm"
sm_access_token = grafana_synthetic_monitoring_installation.sm_stack.sm_access_token
sm_url = grafana_synthetic_monitoring_installation.sm_stack.stack_sm_api_url
}
data "grafana_synthetic_monitoring_probes" "main" {
provider = grafana.sm
depends_on = [grafana_synthetic_monitoring_installation.sm_stack]
}
metrics_publisher_key
(String, Sensitive) The Grafana Cloud access policy with the following scopes: stacks:read
, metrics:write
, logs:write
, traces:write
. This is used to publish metrics and logs to Grafana Cloud stack.stack_id
(String) The ID or slug of the stack to install SM on.stack_sm_api_url
(String) The URL of the SM API to install SM on. This depends on the stack region, find the list of API URLs here: https://grafana.com/docs/grafana-cloud/testing/synthetic-monitoring/set-up/set-up-private-probes/#probe-api-server-url. A static mapping exists in the provider but it may not contain all the regions. If it does contain the stack's region, this field is computed automatically and readable.id
(String) The ID of this resource.sm_access_token
(String) Generated token to access the SM API.