docs/sources/as-code/infrastructure-as-code/terraform/terraform-knowledge-graph/getting-started.md
Learn how to configure Terraform to manage Grafana Cloud Knowledge Graph resources. This guide walks you through setting up the Grafana Terraform provider and preparing your environment.
Before you begin, ensure you have the following:
{{< admonition type="note" >}} All Terraform configuration files should be saved in the same directory. {{< /admonition >}}
This Terraform configuration sets up the Grafana provider to provide necessary authentication when managing knowledge graph resources.
You can reuse a similar setup to the one described in Creating and managing a Grafana Cloud stack using Terraform to set up a service account and a token.
Create a Service account and token in Grafana.
To create a new one, refer to Service account tokens.
Create a file named main.tf and add the following:
terraform {
required_providers {
grafana = {
source = "grafana/grafana"
version = ">= 2.9.0"
}
}
}
provider "grafana" {
alias = "asserts"
url = "<Stack-URL>"
auth = "<Service-account-token>"
stack_id = "<Stack-ID>"
}
Replace the following field values:
<Stack-URL> with the URL of your Grafana stack (for example, https://my-stack.grafana.net/)<Service-account-token> with the service account token that you created<Stack-ID> with your Grafana Cloud stack ID{{< admonition type="note" >}}
The stack_id parameter is required for Knowledge Graph resources to identify the stack where the resources belong.
{{< /admonition >}}
After creating your Terraform configuration files, apply them using the following commands:
Initialize a working directory containing Terraform configuration files:
terraform init
Preview the changes that Terraform makes:
terraform plan
Apply the configuration files:
terraform apply
After applying the configuration, verify your setup by checking that:
When managing Knowledge Graph resources with Terraform, consider the following best practices.
Now that you have configured the Terraform provider, you can start managing knowledge graph resources: