Menu
Grafana Cloud

Provision Grafana Cloud with infrastructure as code

With Grafana Cloud, you can create dashboards via configuration files in source code. This enables you to review code, reuse it, and create better workflows.

Via code, you can declaratively manage what Grafana resources to use. The as-code tools and tutorials that follow show you what do to, to declaratively manage Grafana resources, and incorporate them efficiently into your own use cases.

Grafana Terraform provider

Grafana administrators can manage dashboards and alerts, add synthetic monitoring probes and checks, manage identity and access, and more using the Terraform provider for Grafana.

The following example shows a Terraform configuration for creating a dashboard:

terraform
resource "grafana_dashboard" "metrics" {
  config_json = jsonencode({
    title   = "as-code dashboard"
    uid     = "ascode"
  })
}

This example dashboard only creates the dashboard and does not add any panels or rows. To get started, see the Grafana Terraform provider guides or refer to the Terraform Grafana Provider documentation.

Grafana Terraform provider is best suited for users who are already using Terraform for non-Grafana use cases.

To manage the entire Grafana ecosystem of resources on either Grafana Cloud or OSS deployments of Grafana, it’s best to use the Terraform Grafana provider because it supports the most Grafana resources compared to Grafana’s other as-code solutions.

Known limitations

Managing dashboards isn’t the simplest process—you have to work with long JSON files, which can become difficult to review and update, as well. Grafonnet can help with generating dashboard JSONs that can be used in Terraform, but Grafonnet requires knowing Jsonnet.

Grafana Ansible collection

Resources for configuration management are available for Grafana through the Ansible collection for Grafana. The Grafana Ansible collection can be used to manage a variety of resources, including folders, cloud stacks, and dashboards. You can programmatically manage resources on Grafana that aren’t currently part of the Grafana Ansible collection by writing Ansible playbooks that use the HTTP APIs to manage resources for Grafana.

The following example shows an Ansible configuration for creating a dashboard:

yaml
- name: dashboard as code
  grafana.grafana.dashboard:
    dashboard: { 'title': 'as-code dashboard', 'uid': 'ascode' }
    stack_slug: '{{ stack_slug }}'
    grafana_api_key: '{{ grafana_api_key }}'
    state: present

This example dashboard creates only the dashboard and does not add any panels or rows.

To get started, see the quickstart guides for the Grafana Ansible Collection or check out the collections’s documentation.

Like Terraform, the Grafana Ansible collection is best suited for people already using Ansible for non-Grafana use cases. The collection only works for Grafana Cloud right now, so it makes the most sense for Grafana Cloud customers who want to manage resources declaratively using Ansible.

Known limitations

The Grafana Ansible collection only works for Grafana Cloud and only supports eight resources: API keys, cloud stacks, plugins, dashboards, folders, data sources, alert contact points, and notification policies. This can be a drawback if you want to manage the entire Grafana ecosystem as code with Ansible. As with Terraform, building dashboards is a challenging process.

Grafana Operator

The Grafana Operator is a Kubernetes operator that can provision, manage, and operate Grafana instances and their associated resources within Kubernetes through Custom Resources. This Kubernetes-native tool eases the administration of Grafana, offering a declarative approach to managing dashboards, data sources, and folders. It also automatically syncs the Kubernetes Custom resources and the actual resources in the Grafana Instance. It supports leveraging Grafonnet for generating Grafana dashboard definitions for seamless dashboard configuration as code.

To get started, see the quickstart guides for the Grafana Operator or check out the Grafana Operator’s documentation.

A sample Kubernetes configuration for creating a dashboard using the Grafana operator looks like this:

yaml
apiVersion: integreatly.org/v1alpha1
kind: GrafanaDashboard
metadata:
  name: simple-dashboard
  labels:
    app: grafana
spec:
  instanceSelector:
    matchLabels:
      dashboards: <Grafana-custom-resource-name>
  json: >
    {
      "title": "as-code dashboard",
      “uid” : “ascode”
    }

The Grafana Operator is particularly fitting for:

  • Teams seeking integrated solutions to manage Grafana resources within the Kubernetes cluster ecosystem.
  • Teams employing a GitOps approach, allowing them to treat Grafana configurations as code, stored alongside application manifests for versioned and automated deployments.

Known limitations

While the Grafana Operator simplifies many aspects of operating Grafana and its resources on Kubernetes, its current support is mainly focused on managing dashboards, folders, and data sources. Advanced features like alerting and plugins (only works for OSS) are not supported yet.

Grizzly

Grizzly is a command line tool that allows you to manage your observability resources with code. Grizzly supports Kubernetes-inspired YAML representation for the Grafana resource, which makes it easier to learn. With Grizzly, you can move dashboards within Grafana instances and also retrieve information about already provisioned Grafana resources. Grizzly currently supports:

  • Grafana dashboards and dashboard folders
  • Grafana data sources
  • Prometheus recording rules and alerts in Grafana Cloud
  • Grafana Cloud Synthetic Monitoring checks

Grizzly can also deploy dashboards built in Jsonnet using Grafonnet. (Learn more in the Grafonnet documentation.)

The following example shows a Kubernetes-style Grizzly configuration for creating a dashboard:

yaml
apiVersion: grizzly.grafana.com/v1alpha1
kind: Dashboard
metadata:
  name: as-code-dashboard
spec:
  title: as-code dashboard
  uid: ascode

To get started, see the Grizzly guides or refer to the Grizzly’s documentation.

Grizzly is best suited for users who are either using Jsonnet to manage Grafana resources or those who prefer a Kubernetes-style YAML definition of their Grafana resources.

Known limitations

Grizzly currently doesn’t support Grafana OnCall and Grafana Alerting resources.

Grafana Crossplane provider

Grafana Crossplane provider is built using Terrajet and provides support for all resources supported by the Grafana Terraform provider. It enables users to define Grafana resources as Kubernetes manifests and it also help users who build their GitOps pipelines around Kubernetes manifests using tools like ArgoCD.

To get started with the Grafana Crossplane provider, install Crossplane in the Kubernetes cluster and use this command to install the provider:

shell
kubectl crossplane install provider grafana/crossplane-provider-grafana:v0.1.0

During installation of the provider, CRDs for all the resources supported by the Terraform provider are added to the cluster so users can begin defining their Grafana resources as Kubernetes custom resources. The Crossplane provider ensures that whatever is defined in the custom resource definitions is what is visible in Grafana UI. If any changes are made directly in the UI, the changes will be discarded when the provider resyncs. This helps ensure that whatever is defined declaratively in the cluster will be the source of truth for Grafana resources.

To get started, refer to the examples folder in the Grafana Crossplane repository.

The following example shows a Kubernetes custom resource definition for creating a dashboard:

yaml
apiVersion: grafana.jet.crossplane.io/v1alpha1
kind: Dashboard
metadata:
  name: as-code-dashboard
spec:
  forProvider:
    configJson: |
      {
        "title": "as-code dashboard",
        "uid": "ascode"
      }
  providerConfigRef:
    name: grafana-crossplane-provider

The Grafana Crossplane provider is intended for existing Crossplane users looking to manage Grafana resources from within Kubernetes and as Kubernetes manifests for the GitOps pipelines.

Known limitations

To use the Crossplane provider, you must have the Crossplane CLI and Crossplane installed in the Kubernetes cluster. Note that the Crossplane provider is in an alpha stage, so it has not reached a stable state yet.

Grafana as code comparison

Most of the tools defined here can be used with one another. The following chart compares the properties and tools mentioned above.

Property/ToolGrafana Terraform ProviderGrafana Ansible CollectionGrafana OperatorGrizzlyGrafana Crossplane Provider
Grafana resources supportedAll major Grafana resourcesGrafana Cloud stack, plugins, API keys, dashboards, data sources, and foldersDashboards, Datasources, FoldersSynthetic Monitoring checks, dashboards, data sources, folders, and Prometheus rulesAll major Grafana resources
Tool formatHCL/JSONYAMLYAMLJsonnet/YAML/JSONYAML/JSON
Follows Kubernetes-style manifests
Easy dashboard building process
Manage resources using Kubernetes
Retrieves Grafana resource information
Built-in resource sync process
Recommended forExisting Terraform usersExisting Ansible usersUsers looking to manage Grafana resources from within KubernetesUsers looking to define Grafana resources in a Kubernetes-style YAML and users looking to get built-in workflow support and sync processUsers looking to manage Grafana resources from within Kubernetes