Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions docs/data-sources/cockpit_grafana.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
subcategory: "Cockpit"
page_title: "Scaleway: scaleway_cockpit_grafana"
---

# Data Source: scaleway_cockpit_grafana

Gets information about Scaleway Cockpit's Grafana instance for a specific project.

This data source provides the Grafana URL and project details. Authentication is managed through [Scaleway IAM (Identity and Access Management)](https://www.scaleway.com/en/docs/identity-and-access-management/iam/).

Refer to Cockpit's [product documentation](https://www.scaleway.com/en/docs/observability/cockpit/concepts/) and [API documentation](https://www.scaleway.com/en/developers/api/cockpit/regional-api) for more information.

## Example Usage

### Basic usage

```terraform
data "scaleway_cockpit_grafana" "main" {
project_id = scaleway_account_project.project.id
}

output "grafana_url" {
value = data.scaleway_cockpit_grafana.main.grafana_url
description = "Access Grafana using your Scaleway IAM credentials"
}
```

### Using with default project

```terraform
# Uses the default project from provider configuration
data "scaleway_cockpit_grafana" "main" {}

output "grafana_url" {
value = data.scaleway_cockpit_grafana.main.grafana_url
}
```

### Complete example with Cockpit setup

```terraform
resource "scaleway_account_project" "project" {
name = "my-observability-project"
}

resource "scaleway_cockpit" "main" {
project_id = scaleway_account_project.project.id
}

data "scaleway_cockpit_grafana" "main" {
project_id = scaleway_cockpit.main.project_id
}

output "grafana_connection_info" {
value = {
url = data.scaleway_cockpit_grafana.main.grafana_url
project_id = data.scaleway_cockpit_grafana.main.project_id
}
description = "Use your Scaleway IAM credentials to authenticate"
}
```

## Argument Reference

- `project_id` - (Optional) The ID of the project the Grafana instance is associated with. If not provided, the default project configured in the provider is used.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

- `id` - The ID of the project (same as `project_id`).
- `grafana_url` - The URL to access the Grafana dashboard. Use your Scaleway IAM credentials to authenticate.

## Authentication

To access Grafana, use your Scaleway IAM credentials:

1. Navigate to the `grafana_url` provided by this data source
2. Sign in using your Scaleway account (IAM authentication)
3. Your access level is determined by your IAM permissions on the project

For more information about IAM authentication, see the [Scaleway IAM documentation](https://www.scaleway.com/en/docs/identity-and-access-management/iam/).

29 changes: 16 additions & 13 deletions docs/guides/migration_guide_cockpit_plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ resource "scaleway_cockpit_alert_manager" "alert_manager" {
}
```

**Grafana User:**
**Grafana Access:**

To retrieve the deprecated `grafana_url`, you must create a Grafana user. Creating the user will trigger the creation of the Grafana instance:
~> **Note:** The `scaleway_cockpit_grafana_user` resource is deprecated and will be removed on January 1st, 2026. Grafana authentication is now managed through Scaleway IAM.

To retrieve the Grafana URL, use the `scaleway_cockpit_grafana` data source. Authentication is handled via your Scaleway IAM credentials:

```hcl
resource "scaleway_cockpit_grafana_user" "main" {
data "scaleway_cockpit_grafana" "main" {
project_id = scaleway_account_project.project.id
login = "my-awesome-user"
role = "editor"
}
```

Expand Down Expand Up @@ -172,10 +172,8 @@ resource "scaleway_cockpit_alert_manager" "alert_manager" {
enable_managed_alerts = true
}

resource "scaleway_cockpit_grafana_user" "main" {
data "scaleway_cockpit_grafana" "main" {
project_id = scaleway_account_project.project.id
login = "my-awesome-user"
role = "editor"
}

output "endpoints" {
Expand All @@ -184,8 +182,9 @@ output "endpoints" {
logs = scaleway_cockpit_source.logs.url
traces = scaleway_cockpit_source.traces.url
alert_manager = scaleway_cockpit_alert_manager.alert_manager.alert_manager_url
grafana = scaleway_cockpit_grafana_user.main.grafana_url
grafana = data.scaleway_cockpit_grafana.main.grafana_url
}
description = "Use your Scaleway IAM credentials to authenticate to Grafana"
}
```

Expand All @@ -199,12 +198,16 @@ To import an existing `scaleway_cockpit_source` resource:
terraform import scaleway_cockpit_source.main fr-par/11111111-1111-1111-1111-111111111111
```

### Import a Grafana User
### Grafana Data Source

To import an existing Grafana user:
~> **Note:** The `scaleway_cockpit_grafana_user` resource is deprecated. Grafana authentication is now handled via Scaleway IAM, and no import is needed for the data source.

```bash
terraform import scaleway_cockpit_grafana_user.main 11111111-1111-1111-1111-111111111111
The `scaleway_cockpit_grafana` data source automatically retrieves Grafana information. No import is required:

```hcl
data "scaleway_cockpit_grafana" "main" {
project_id = scaleway_account_project.project.id
}
```

## Conclusion
Expand Down
41 changes: 22 additions & 19 deletions docs/resources/cockpit.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ page_title: "Scaleway: scaleway_cockpit"

- `scaleway_cockpit_source` for managing data sources (metrics, logs, traces)
- `scaleway_cockpit_alert_manager` for managing alert manager
- `scaleway_cockpit_grafana_user` for managing Grafana users
- `scaleway_cockpit_grafana` data source for accessing Grafana (authentication via IAM)

For detailed migration instructions, see the [Cockpit Migration Guide](../guides/migration_guide_cockpit_plan.md).

Expand All @@ -20,7 +20,7 @@ If you have created customized dashboards with data for your Scaleway resources
-> **Note:**
From January 1st 2025, Cockpit plans have been deprecated. You can now edit the retention period for all your datasources (metrics, logs, and traces) separately. Refer to our product documentation for more information on [possible retention values](https://www.scaleway.com/en/docs/cockpit/concepts/#retention) and [pricing](https://www.scaleway.com/en/docs/cockpit/faq/#how-am-i-billed-for-increasing-data-retention-period).

Please note that even if you provide the grafana_url, it will only be active if a [Grafana user](../resources/cockpit_grafana_user.md) is created first. Make sure to create a Grafana user in your Cockpit instance to enable full access to Grafana.
~> **Note:** The `scaleway_cockpit_grafana_user` resource is deprecated. Use the [`scaleway_cockpit_grafana` data source](../data-sources/cockpit_grafana.md) to retrieve the Grafana URL and authenticate using your Scaleway IAM credentials.

The `scaleway_cockpit` resource allows you to create and manage Scaleway Cockpit instances.

Expand Down Expand Up @@ -53,27 +53,30 @@ resource "scaleway_cockpit" "main" {
}
```

### Use the Grafana Terraform provider
### Use the Grafana Terraform provider (Deprecated)

```terraform
// Use the Grafana Terraform provider to create a Grafana user and a Grafana folder in the default Project's Cockpit
~> **Note:** This example is deprecated. Use the `scaleway_cockpit_grafana` data source with IAM authentication instead.

resource "scaleway_cockpit_grafana_user" "main" {
```terraform
// Old approach (deprecated) - Using scaleway_cockpit_grafana_user
// resource "scaleway_cockpit_grafana_user" "main" {
// project_id = scaleway_cockpit.main.project_id
// login = "example"
// role = "editor"
// }
//
// provider "grafana" {
// url = scaleway_cockpit.main.endpoints.0.grafana_url
// auth = "${scaleway_cockpit_grafana_user.main.login}:${scaleway_cockpit_grafana_user.main.password}"
// }

// New approach - Use scaleway_cockpit_grafana data source with IAM auth
data "scaleway_cockpit_grafana" "main" {
project_id = scaleway_cockpit.main.project_id
login = "example"
role = "editor"
}

resource "scaleway_cockpit" "main" {}

provider "grafana" {
url = scaleway_cockpit.main.endpoints.0.grafana_url
auth = "${scaleway_cockpit_grafana_user.main.login}:${scaleway_cockpit_grafana_user.main.password}"
}

resource "grafana_folder" "test_folder" {
title = "Test Folder"
}
// Note: Grafana provider with IAM auth requires proper token setup
// See Grafana provider documentation for IAM authentication
```

## Argument Reference
Expand Down Expand Up @@ -104,7 +107,7 @@ This resource is deprecated and will be removed after January 1st, 2025. To migr

- `scaleway_cockpit_source` for managing data sources (metrics, logs, traces)
- `scaleway_cockpit_alert_manager` for managing alert manager
- `scaleway_cockpit_grafana_user` for managing Grafana users
- `scaleway_cockpit_grafana` data source for accessing Grafana (with IAM authentication)

## Import

Expand Down
29 changes: 28 additions & 1 deletion docs/resources/cockpit_grafana_user.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,40 @@ page_title: "Scaleway: scaleway_cockpit_grafana_user"

# Resource: scaleway_cockpit_grafana_user

~> **Deprecated:** This resource is deprecated and will be removed on **January 1st, 2026**.

~> **Migration Guide:** Grafana authentication is now managed through [Scaleway IAM (Identity and Access Management)](https://www.scaleway.com/en/docs/identity-and-access-management/iam/). To access your Grafana instance, use the [`scaleway_cockpit_grafana` data source](../data-sources/cockpit_grafana.md) to retrieve the Grafana URL and authenticate using your Scaleway IAM credentials.

The `scaleway_cockpit_grafana_user` resource allows you to create and manage [Grafana users](https://www.scaleway.com/en/docs/observability/cockpit/concepts/#grafana-users) in Scaleway Cockpit.

Refer to Cockpit's [product documentation](https://www.scaleway.com/en/docs/observability/cockpit/concepts/) and [API documentation](https://www.scaleway.com/en/developers/api/cockpit/regional-api) for more information.

## Example Usage

### Create a Grafana user
### Migration to IAM Authentication

Instead of managing Grafana users, retrieve your Grafana URL using the data source:

```terraform
# Old approach (deprecated)
# resource "scaleway_cockpit_grafana_user" "main" {
# project_id = scaleway_account_project.project.id
# login = "my-awesome-user"
# role = "editor"
# }

# New approach - Use IAM authentication
data "scaleway_cockpit_grafana" "main" {
project_id = scaleway_account_project.project.id
}

output "grafana_url" {
value = data.scaleway_cockpit_grafana.main.grafana_url
description = "Access Grafana using your Scaleway IAM credentials"
}
```

### Create a Grafana user (Deprecated)

The following command allows you to create a Grafana user within a specific Scaleway Project.

Expand Down
2 changes: 1 addition & 1 deletion internal/services/cockpit/cockpit.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func ResourceCockpit() *schema.Resource {
},
},
},
DeprecationMessage: "The scaleway_cockpit resource is deprecated and will be removed after January 1st, 2025. Use the new specialized resources instead: scaleway_cockpit_source, scaleway_cockpit_alert_manager, and scaleway_cockpit_grafana_user.",
DeprecationMessage: "The scaleway_cockpit resource is deprecated and will be removed after January 1st, 2025. Use the new specialized resources instead: scaleway_cockpit_source and scaleway_cockpit_alert_manager. For Grafana access, use the scaleway_cockpit_grafana data source with IAM authentication (the scaleway_cockpit_grafana_user resource is also deprecated).",
}
}

Expand Down
37 changes: 15 additions & 22 deletions internal/services/cockpit/cockpit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,21 @@ func TestAccCockpit_WithSourceEndpoints(t *testing.T) {
type = "traces"
}

resource "scaleway_cockpit_alert_manager" "alert_manager" {
project_id = scaleway_account_project.project.id
enable_managed_alerts = true
}

resource "scaleway_cockpit_grafana_user" "main" {
project_id = scaleway_account_project.project.id
login = "cockpit_test_endpoint"
role = "editor"
}

resource "scaleway_cockpit" "main" {
project_id = scaleway_account_project.project.id
plan = "premium"
depends_on = [
scaleway_cockpit_source.metrics,
scaleway_cockpit_source.logs,
scaleway_cockpit_source.traces,
scaleway_cockpit_alert_manager.alert_manager,
scaleway_cockpit_grafana_user.main
]
}
resource "scaleway_cockpit_alert_manager" "alert_manager" {
project_id = scaleway_account_project.project.id
enable_managed_alerts = true
}

resource "scaleway_cockpit" "main" {
project_id = scaleway_account_project.project.id
plan = "premium"
depends_on = [
scaleway_cockpit_source.metrics,
scaleway_cockpit_source.logs,
scaleway_cockpit_source.traces,
scaleway_cockpit_alert_manager.alert_manager
]
}
`,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("scaleway_cockpit.main", "plan", "premium"),
Expand Down
66 changes: 66 additions & 0 deletions internal/services/cockpit/grafana_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package cockpit

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/scaleway/scaleway-sdk-go/api/cockpit/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/verify"
)

func DataSourceCockpitGrafana() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceCockpitGrafanaRead,
Schema: map[string]*schema.Schema{
"project_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The project ID associated with the Grafana instance",
ValidateDiagFunc: verify.IsUUID(),
},
"grafana_url": {
Type: schema.TypeString,
Computed: true,
Description: "The URL to access the Grafana dashboard",
},
},
}
}

func dataSourceCockpitGrafanaRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
api, err := NewGlobalAPI(m)
if err != nil {
return diag.FromErr(err)
}

projectID := d.Get("project_id").(string)
if projectID == "" {
defaultProjectID, err := getDefaultProjectID(ctx, m)
if err != nil {
return diag.FromErr(err)
}

projectID = defaultProjectID
}

grafana, err := api.GetGrafana(&cockpit.GlobalAPIGetGrafanaRequest{
ProjectID: projectID,
}, scw.WithContext(ctx))
if err != nil {
if httperrors.Is404(err) {
return diag.Errorf("Grafana instance not found for project %s. Ensure that Cockpit is activated for this project.", projectID)
}

return diag.FromErr(err)
}

d.SetId(projectID)
_ = d.Set("project_id", projectID)
_ = d.Set("grafana_url", grafana.GrafanaURL)

return nil
}
Loading
Loading