NavigationContentFooter
Jump toSuggest an edit

Using Cockpit with Terraform

Reviewed on 02 August 2024Published on 04 June 2024
  • observability
  • cockpit
  • terraform
  • grafana
  • monitoring

In this tutorial, you will learn how to get started with Cockpit using a Terraform configuration file containing all the code you need to create:

  • A Grafana user
  • A folder in the Grafana user interface
  • A Cockpit token with permission to query and push metrics
  • A metric data source

Before you start

To complete the actions presented below, you must have:

  • A Scaleway account logged into the console
  • Owner status or IAM permissions allowing you to perform actions in the intended Organization
  • Configured an SSH key
  • Installed Terraform on your local machine

Configuring your environment

Clone the repository

Open a terminal on your local machine and clone the cockpit-terraform repository containing the Terraform configuration file:

git clone git@github.com:scaleway/cockpit-terraform.git

Add your information

  1. Access the main.tf file inside the cockpit-terraform directory. We recommend that you do it manually, as you need to add your values.
  2. Replace xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx line 5, with your Scaleway Project ID.
  3. Replace your-grafana-user line 28, with a name for the Grafana user you will be creating.
  4. Replace Test Folder line 39, with a name of your choice.
  5. Replace your-push-token line 45, with a name for your Cockpit token.
  6. Replace your-data-source line 57, with a name for your metric data source.
  7. Save your changes and close the file.

Build and deploy your infrastructure

  1. Open a terminal and access the cockpit-terraform file:

    cd cockpit-terraform
  2. Run the following command to download the dependencies and initialize Terraform:

    terraform init
  3. Run the following command to deploy your infrastructure. Terraform generates an execution plan showing you what actions are about to be performed.

    terraform apply
    Terraform used the selected providers to generate the following execution plan.
    Resource actions are indicated with the following symbols:
    + create
    Terraform will perform the following actions:
    # grafana_folder.folder_test will be created
    + resource "grafana_folder" "folder_test" {
    + id = (known after apply)
    + prevent_destroy_if_not_empty = false
    + title = "Test Folder"
    + uid = (known after apply)
    + url = (known after apply)
    }
    # scaleway_cockpit.main will be created
    + resource "scaleway_cockpit" "main" {
    + endpoints = (known after apply)
    + id = (known after apply)
    + plan_id = (known after apply)
    + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    + push_url = (known after apply)
    }
    # scaleway_cockpit_grafana_user.main will be created
    + resource "scaleway_cockpit_grafana_user" "main" {
    + id = (known after apply)
    + login = "your-grafana-user"
    + password = (sensitive value)
    + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    + role = "editor"
    }
    # scaleway_cockpit_source.main will be created
    + resource "scaleway_cockpit_source" "main" {
    + created_at = (known after apply)
    + id = (known after apply)
    + name = "your-data-source"
    + origin = (known after apply)
    + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    + region = (known after apply)
    + synchronized_with_grafana = (known after apply)
    + type = "metrics"
    + updated_at = (known after apply)
    + url = (known after apply)
    }
    # scaleway_cockpit_token.main will be created
    + resource "scaleway_cockpit_token" "main" {
    + created_at = (known after apply)
    + id = (known after apply)
    + name = "your-push-token"
    + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    + region = (known after apply)
    + secret_key = (sensitive value)
    + updated_at = (known after apply)
    + scopes {
    + query_logs = false
    + query_metrics = true
    + query_traces = false
    + setup_alerts = false
    + setup_logs_rules = false
    + setup_metrics_rules = false
    + write_logs = false
    + write_metrics = true
    + write_traces = false
    }
    }
    Plan: 5 to add, 0 to change, 0 to destroy.
    Do you want to perform these actions?
    Terraform will perform the actions described above.
    Only 'yes' will be accepted to approve.
  4. Type yes and Enter to apply the changes. An output similar to the following displays:

    Apply complete! Resources: 4 added, 0 changed, 0 destroyed.
    Outputs:
    cockpit_url = "https://xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.dashboard.obs.fr-par.scw.cloud"
    cockpit_user_login = "your-grafana-user"
    cockpit_user_password = "your-grafana-user-password"
    Important

    We recommend that you store your Grafana user password displayed in the output in a safe place so you do not lose it.

Visualize your data in Grafana

  1. Click Cockpit in the Observability section of the console. The Cockpit overview page displays.
  2. Click the Grafana users tab. Your newly created user displays.
  3. Click Open dashboards in the top right-hand corner.
  4. Log in to Grafana using your Grafana credentials. The Cockpit Dashboards page displays.
  5. Click Toggle menu in the top left-hand corner, then click Dashboards. Your newly created folder displays.
  6. Click Toggle menu in the top left-hand corner, then click Connections.
  7. Click Data sources. Your metrics data source displays. You can now push your data into it, and build a dashboard to visualize your metrics.
Was this page helpful?
API DocsScaleway consoleDedibox consoleScaleway LearningScaleway.comPricingBlogCareers
© 2023-2024 – Scaleway