We recommend that you store your Grafana user password displayed in the output in a safe place so you do not lose it.
Jump toSuggest an edit
Using Cockpit with Terraform
Reviewed on 02 August 2024 • Published 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
- Access the
main.tf
file inside thecockpit-terraform
directory. We recommend that you do it manually, as you need to add your values. - Replace
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
line 5, with your Scaleway Project ID. - Replace
your-grafana-user
line 28, with a name for the Grafana user you will be creating. - Replace
Test Folder
line 39, with a name of your choice. - Replace
your-push-token
line 45, with a name for your Cockpit token. - Replace
your-data-source
line 57, with a name for your metric data source. - Save your changes and close the file.
Build and deploy your infrastructure
-
Open a terminal and access the
cockpit-terraform
file:cd cockpit-terraform -
Run the following command to download the dependencies and initialize Terraform:
terraform init -
Run the following command to deploy your infrastructure. Terraform generates an execution plan showing you what actions are about to be performed.
terraform applyTerraform used the selected providers to generate the following execution plan.Resource actions are indicated with the following symbols:+ createTerraform 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. -
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
Visualize your data in Grafana
- Click Cockpit in the Observability section of the console. The Cockpit overview page displays.
- Click the Grafana users tab. Your newly created user displays.
- Click Open dashboards in the top right-hand corner.
- Log in to Grafana using your Grafana credentials. The Cockpit Dashboards page displays.
- Click Toggle menu in the top left-hand corner, then click Dashboards. Your newly created folder displays.
- Click Toggle menu in the top left-hand corner, then click Connections.
- 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?