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/latest/as-code/observability-as-code/grafana-cli/gcx/guides/dashboards-as-code.md, or by sending Accept: text/markdown to https://grafana.com/docs/grafana/latest/as-code/observability-as-code/grafana-cli/gcx/guides/dashboards-as-code/. 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 dashboards as code with gcx
With this workflow, you can define and manage dashboards as code, saving them to a version control system like Git. This is useful for teams that want to maintain a history of changes, collaborate on dashboard design, and ensure consistency across environments.
Before you begin
In order to use the gcx dev serve functionality, you need to enable a feature toggle in your configuration file:
[feature_toggles]
kubernetesDashboards = trueRefer to Configure Grafana to learn more about enabling feature toggles.
Although the local preview proxy supports service account token, Basic, and mTLS contexts, use a service account token instead of OAuth for gcx dev serve. OAuth is rejected before startup until refresh-token rotation can be persisted safely by the long-running server.
Workflow
To manage dashboards as code with gcx follow these steps:
- Use a dashboard generation script (for example, with the Foundation SDK). You can find an example implementation in the Grafana as code hands-on lab repository.
- Serve and preview the output of the dashboard generator locally:shell
gcx config use-context YOUR_CONTEXT # for example "dev" gcx dev serve --script 'go run scripts/generate-dashboard.go' --watch './scripts' - When the output looks correct, generate dashboard manifest files:shell
go run scripts/generate-dashboard.go --generate-resource-manifests --output './resources' - Push the generated resources to your Grafana instance:shell
gcx config use-context YOUR_CONTEXT # for example "dev" gcx resources push -p ./resources/
Was this page helpful?
Related resources from Grafana Labs


