---
title: "Dashboards as code | Grafana Cloud documentation"
description: "Use gcx to manage dashboards as code."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/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:

ini ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```ini
[feature_toggles]
kubernetesDashboards = true
```

Refer to [Configure Grafana](/docs/grafana/latest/setup-grafana/configure-grafana/#feature_toggles) 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:

1. Use a dashboard generation script (for example, with the [Foundation SDK](https://github.com/grafana/grafana-foundation-sdk)). You can find an example implementation in the Grafana as code [hands-on lab repository](https://github.com/grafana/dashboards-as-code-workshop/tree/main/part-one-golang-starter).
2. Serve and preview the output of the dashboard generator locally:
   
   shell ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```shell
   gcx config use-context YOUR_CONTEXT  # for example "dev"
   gcx dev serve --script 'go run scripts/generate-dashboard.go' --watch './scripts'
   ```
3. When the output looks correct, generate dashboard manifest files:
   
   shell ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```shell
   go run scripts/generate-dashboard.go --generate-resource-manifests --output './resources'
   ```
4. Push the generated resources to your Grafana instance:
   
   shell ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```shell
   gcx config use-context YOUR_CONTEXT  # for example "dev"
   gcx resources push -p ./resources/
   ```
