Manage analytics dashboards with Terraform
Use the konnect_dashboard
resource from the terraform provider to define and manage dashboards.
You can import existing dashboards or create new ones with configurable chart layouts, titles, and filters.
Prerequisites
Series Prerequisites
This page is part of the Create custom dashboards with Konnect analytics series.
Complete the previous page, Create a dashboard from a template before completing this page.
Terraform
This how-to requires you to install Terraform.
Kong Konnect
This is a Konnect tutorial and requires a Konnect personal access token.
-
Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.
-
Export your token to an environment variable:
export KONNECT_TOKEN='YOUR_KONNECT_PAT'
-
Create an
auth.tf
file that configures thekong/konnect
Terraform provider. Changeserver_url
if you are using a region other thanus
:echo ' terraform { required_providers { konnect = { source = "kong/konnect" } konnect-beta = { source = "kong/konnect-beta" } } } provider "konnect" { server_url = "https://us.api.konghq.com" } provider "konnect-beta" { server_url = "https://us.api.konghq.com" } ' > auth.tf
-
Next, initialize your project and download the provider:
terraform init
The provider automatically uses the KONNECT_TOKEN
environment variable if it is available. If you would like to use a custom authentication token, set the personal_access_token
field alongside server_url
in the provider
block.
Roles and permissions
This guide requires being an Organization Admin or belonging to the Analytics admin team.
An existing custom dashboard
This guide requires an existing dashboard in Konnect. You can create one using the Create a custom dashboard guide.
Get the dashboard ID
In this tutorial, we’ll export an existing dashboard in Konnect and modify it with Terraform, so you can integrate Konnect Analytics with your existing workflow.
Managing dashboards with Terraform requires the dashboard ID of the target dashboard:
- Get an existing dashboard ID from the Konnect URL of your dashboard. It appears at the end of the URL when viewing the dashboard in the UI:
https://cloud.konghq.com/us/analytics/dashboards/$DASHBOARD_ID
- Export the dashboard ID into an environment variable to be used later:
export DASHBOARD_ID='fe1b6b51-2e7e-44d6-bfa5-CC93489b3eed'
Import the dashboard
Now configure Terraform to import a dashboard from Konnect.
echo '
import {
provider = "konnect-beta"
to = konnect_dashboard.service_dashboard_template
id = "8e66b804-a060-466a-aa6c-145e7f696228"
}
' >> import.tf
Be sure to replace the id
with the id
you exported for your dashboard.
Generate the Terraform configuration
- Initialize Terraform:
terraform init
- Generate the Terraform configuration for the dashboard:
terraform plan -generate-config-out=create_dashboard.tf
This creates a new file named create_dashboard.tf
that contains the Terraform resource definition for the imported dashboard.
Configure the dashboard
The new create_dashboard.tf
file contains information about your dashboard. You can use this file to make changes to the dashboard in Konnect with Terraform:
}
layout = {
position = {
col = 4
row = 6
}
size = {
cols = 2
rows = 2
}
}
type = "chart"
}
},
]
}
labels = null
name = "Quick summary dashboard"
}
You can add a label to the dashboard by modifying the file to replace labels = null
with the following:
labels = {
test = "test"
}
Validate
To validate that your changes are working, make an update in the generated Terraform file (for example, change a chart label).
- Run the following command to apply the update:
terraform apply -auto-approve
- After the change is applied, return to the Konnect dashboard manager to confirm the “test” label has been added to the dashboard.