docs/sources/as-code/infrastructure-as-code/terraform/terraform-cloud-provider-o11y.md
Manage Cloud Provider Observability, including Amazon CloudWatch and Microsoft Azure resources, in Grafana Cloud using Terraform. For more information on Cloud Provider Observability, refer to the Cloud Provider Observability documentation.
Before you begin, ensure you have the following:
{{< admonition type="note" >}} Save all of the following Terraform configuration files in the same directory. {{< /admonition >}}
The Grafana Provider is a logical abstraction of an upstream API that you can use to interact with Grafana Cloud resources. You must configure it with the following information:
To configure authentication for the Grafana Provider:
Create a Grafana Cloud access policy and token.
integration-management:readintegration-management:writestacks:readmetrics:writelogs:writeintegration-management:readintegration-management:writestacks:readlogs:writeObtain the regional Cloud Provider API endpoint.
curl -sH "Authorization: Bearer <Access Token from previous step>" "https://grafana.com/api/instances" | \
jq '[.items[]|{stackName: .slug, clusterName:.clusterSlug, cloudProviderAPIURL: "https://cloud-provider-api-\(.clusterSlug).grafana.net"}]'
Create a file named cloud-provider.tf and add the following code block:
terraform {
required_providers {
grafana = {
source = "grafana/grafana"
}
}
}
provider "grafana" {
cloud_api_url = "<CLOUD_PROVIDER_API_URL>"
cloud_access_policy_token = "<CLOUD_ACCESS_POLICY_TOKEN>"
}
Create a variables.tf file and paste the <CLOUD_ACCESS_POLICY_TOKEN> and <CLOUD_PROVIDER_API_URL variables with your values.
Run the following Terraform command:
terraform apply -var-file="variables.tf"
To find instructions for configuring specific Amazon CloudWatch and Microsoft Azure resources in Cloud Provider Observability using Terraform, refer to the following documents:
You can define the following Cloud Provider Observability resources and data sources using Terraform:
| Resource name | Description |
|---|---|
grafana_cloud_provider_aws_account | Represents an AWS IAM role that authorizes Grafana Cloud to pull Amazon CloudWatch metrics for a set of regions. Usually, there's one of these resources per configured AWS account. For a full reference of this resource, refer to the Terraform Grafana Provider reference documentation. |
grafana_cloud_provider_aws_cloudwatch_scrape_job | Represents a Grafana AWS scrape job. This configures Grafana to fetch a list of metrics and statistics for one or many AWS services, and for a given grafana_cloud_provider_aws_account. For a full reference of this resource, refer to the Terraform Grafana Provider reference documentation. |
grafana_cloud_provider_aws_resource_metadata_scrape_job | Represents a Grafana AWS Resource Metadata scrape job. This resource configures Grafana to fetch resource metadata for one or multiple AWS services, for a given grafana_cloud_provider_aws_account. For a full reference of this resource, refer to the Terraform Grafana Provider reference documentation. |
grafana_cloud_provider_azure_credential | A resource representing an Azure Service Principal credential used by Grafana Cloud to pull Azure Monitor metrics from one or more subscriptions. For a full reference of this resource, refer to the Terraform Grafana Provider resource documentation. |