Slide 2 of 4

GitHub Actions workflow

Complete workflow

You can deploy dashboards with a single terraform apply. But if someone still has to remember to run that command after every change, you haven’t removed the human bottleneck. Now you’ll automate the full dashboard lifecycle with GitHub Actions.

This workflow generates and deploys your dashboards. It runs in two cases: when you open or update a pull request, and when commits are pushed to main. On a pull request, it runs generate and plan to preview the changes. On a push to main, it also runs apply to deploy them.

YAML
name: Deploy Grafana Dashboards

on:
  push:
    branches: [main]
  pull_request:

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version: '1.24'

      - name: Generate dashboard JSON
        run: go run main.go

      - name: Setup Terraform
        uses: hashicorp/setup-terraform@v1

      - name: Terraform Init
        run: terraform init

      - name: Terraform Plan
        run: terraform plan -input=false -no-color

      - name: Terraform Apply
        if: github.ref == 'refs/heads/main'
        run: terraform apply -auto-approve
        env:
          GRAFANA_AUTH: ${{ secrets.GRAFANA_TOKEN }}

Step breakdown

Each step in the workflow handles one stage of the generate-plan-apply pipeline.

StepPurpose
CheckoutAccess your repository code
Set up GoInstall the language runtime for SDK code
Generate JSONRun your SDK code to produce dashboard files
Terraform InitDownload the Grafana provider
Plan/ApplyPreview or deploy dashboard changes

The if: github.ref == 'refs/heads/main' condition on the apply step gates deployment: plan runs on every push, but apply runs only when changes land on main. Pull requests get a plan preview without deploying anything.

Alternative CI systems

You can adapt this to other CI systems (GitLab CI, CircleCI, Jenkins) by translating the same five steps. Your Foundation SDK code and Terraform configuration stay the same regardless of which CI tool runs them.

Script

Here’s a complete GitHub Actions workflow that generates and deploys dashboards. It runs whenever you push commits to main or open a pull request.

The workflow has five key steps. First, it checks out your repository. Then it sets up Go (or TypeScript if that’s your language) to run the SDK code. Third, it runs your dashboard generator, which produces the JSON files. Fourth, it initializes Terraform and runs terraform plan to preview changes. Finally, on pushes to main, it runs terraform apply to deploy.

The conditional logic is straightforward: plan runs on every push, but apply only runs when changes land on main. This means pull requests get a plan preview without deploying anything.

You can adapt this to other CI systems (GitLab CI, CircleCI, Jenkins) by translating the same five steps. The Foundation SDK code and Terraform configuration stay the same regardless of which CI tool runs them.