Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a963535
feat(cockpit): add preconfigured_alert_ids field and deprecate enable…
jremy42 Nov 21, 2025
8953152
feat(cockpit): add default_preconfigured_alert_ids field to track API…
jremy42 Nov 21, 2025
150fd72
fix(cockpit): handle permission errors gracefully in alert manager read
jremy42 Nov 21, 2025
fe15631
feat: compress VCR cassettes for cockpit alert manager tests
jremy42 Nov 24, 2025
14b43a5
feat: integrate SDK waiters for preconfigured alerts and remove obsol…
jremy42 Nov 24, 2025
9046217
chore: update go.mod and go.sum for SDK waiters integration
jremy42 Nov 24, 2025
5514792
Merge branch 'master' into feat/cockpit-preconfigured-alerts
jremy42 Nov 24, 2025
21b764e
feat: align preconfigured alerts diff with user selections
jremy42 Nov 24, 2025
bd93405
feat: update waiters for new SDK fields
jremy42 Nov 24, 2025
46c1fb6
docs: fix cockpit preconfigured alert Markdown indentation
jremy42 Nov 24, 2025
a428dbf
chore: gofmt cockpit alert manager and data source
jremy42 Nov 24, 2025
4c022ef
chore: run go mod tidy
jremy42 Nov 24, 2025
5f6abb7
chore: satisfy golangci-lint for cockpit updates
jremy42 Nov 24, 2025
2fb0674
chore: compress data source cockpit basic cassette
jremy42 Nov 24, 2025
5c597ca
chore: fix lint spacing in alert manager test
jremy42 Nov 24, 2025
b8e7137
chore: fix cockpit alert manager cassette validation
jremy42 Nov 24, 2025
937dc09
docs: remove trailing blank line in cockpit migration guide
jremy42 Nov 24, 2025
7eb981f
docs: drop trailing newline in cockpit migration guide
jremy42 Nov 24, 2025
d47b4e5
docs: add newline at EOF for cockpit guide
jremy42 Nov 24, 2025
b10fe86
Merge branch 'master' into feat/cockpit-preconfigured-alerts
jremy42 Nov 24, 2025
151f194
Merge branch 'master' into feat/cockpit-preconfigured-alerts
jremy42 Nov 27, 2025
67e08d2
feat: align cockpit migration guide formatting
jremy42 Nov 27, 2025
265bcce
feat: restore legacy enable_managed_alerts behavior
jremy42 Nov 27, 2025
2c3a10a
chore: run go mod tidy
jremy42 Nov 27, 2025
07e1968
feat: fix alert_manager to use proper ID parsing helpers
jremy42 Nov 28, 2025
af25fdc
chore: fix lint whitespace in alert_manager
jremy42 Nov 28, 2025
dd9b909
chore: compress cockpit basic data source cassette
jremy42 Nov 28, 2025
d03ff3e
chore: skip legacy managed alerts test due to API 500 errors
jremy42 Nov 28, 2025
c913c67
chore: remove legacy managed alerts test cassette
jremy42 Nov 28, 2025
a1d5a90
docs: clarify legacy managed alerts behavior
jremy42 Nov 28, 2025
b078f00
docs: clarify legacy managed alerts enables all preconfigured alerts
jremy42 Nov 28, 2025
a9b8e33
docs: clarify legacy managed alerts enables all preconfigured alerts
jremy42 Nov 28, 2025
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
101 changes: 101 additions & 0 deletions docs/data-sources/cockpit_preconfigured_alert.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
subcategory: "Cockpit"
page_title: "Scaleway: scaleway_cockpit_preconfigured_alert"
---

# Data Source: scaleway_cockpit_preconfigured_alert

Gets information about preconfigured alert rules available in Scaleway Cockpit.

Preconfigured alerts are ready-to-use alert rules that monitor common metrics for Scaleway services.
You can enable these alerts in your Alert Manager using the `scaleway_cockpit_alert_manager` resource.

For more information, 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).

## Example Usage

### Basic usage

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

output "available_alerts" {
value = data.scaleway_cockpit_preconfigured_alert.main.alerts
}
```

### Filter by status

```terraform
data "scaleway_cockpit_preconfigured_alert" "enabled" {
project_id = scaleway_account_project.project.id
rule_status = "enabled"
}

data "scaleway_cockpit_preconfigured_alert" "disabled" {
project_id = scaleway_account_project.project.id
rule_status = "disabled"
}
```

### Use with Alert Manager

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

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

data "scaleway_cockpit_preconfigured_alert" "all" {
project_id = scaleway_cockpit.main.project_id
}

resource "scaleway_cockpit_alert_manager" "main" {
project_id = scaleway_cockpit.main.project_id

# Enable specific alerts by their preconfigured_rule_id
preconfigured_alert_ids = [
for alert in data.scaleway_cockpit_preconfigured_alert.all.alerts :
alert.preconfigured_rule_id
if alert.product_name == "instance" && alert.rule_status == "disabled"
]

contact_points {
email = "alerts@example.com"
}
}
```

## Argument Reference

- `project_id` - (Optional) The ID of the project the alerts are associated with. If not provided, the default project configured in the provider is used.
- `region` - (Optional, defaults to provider region) The region in which the alerts exist.
- `data_source_id` - (Optional) Filter alerts by data source ID.
- `rule_status` - (Optional) Filter alerts by rule status. Valid values are `enabled` or `disabled`.

## Attributes Reference

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

- `id` - The ID of the resource (project ID with region).
- `alerts` - List of preconfigured alerts. Each alert contains:
- `name` - Name of the alert rule.
- `rule` - PromQL expression defining the alert condition.
- `duration` - Duration for which the condition must be true before the alert fires (e.g., "5m").
- `rule_status` - Status of the alert rule (`enabled`, `disabled`, `enabling`, `disabling`).
- `state` - Current state of the alert (`inactive`, `pending`, `firing`).
- `annotations` - Map of annotations attached to the alert.
- `preconfigured_rule_id` - Unique identifier of the preconfigured rule. Use this ID in `scaleway_cockpit_alert_manager` resource.
- `display_name` - Human-readable name of the alert.
- `display_description` - Human-readable description of the alert.
- `product_name` - Scaleway product associated with the alert (e.g., "instance", "rdb", "kubernetes").
- `product_family` - Family of the product (e.g., "compute", "storage", "network").
- `data_source_id` - ID of the data source containing the alert rule.



167 changes: 167 additions & 0 deletions docs/guides/migration_guide_cockpit_alert_manager.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
---
page_title: "Cockpit Alert Manager Migration Guide"
---

# Cockpit Alert Manager Migration Guide

This guide explains how to migrate from the deprecated `enable_managed_alerts` field to the new `preconfigured_alert_ids` field in the `scaleway_cockpit_alert_manager` resource.

## Background

The `enable_managed_alerts` field is being deprecated in favor of a more flexible approach using `preconfigured_alert_ids`. This change provides:

- **Granular control**: Select specific alerts instead of enabling all managed alerts
- **Better visibility**: Explicitly declare which alerts are enabled in your Terraform configuration
- **Improved state management**: Terraform accurately tracks which alerts are active

## Migration Steps

### Before Migration (Deprecated)

```terraform
resource "scaleway_cockpit_alert_manager" "main" {
project_id = scaleway_account_project.project.id
enable_managed_alerts = true

contact_points {
email = "alerts@example.com"
}
}
```

### After Migration (Recommended)

#### Step 1: List Available Preconfigured Alerts

Use the data source to discover available alerts:

```terraform
data "scaleway_cockpit_preconfigured_alert" "all" {
project_id = scaleway_account_project.project.id
}

output "available_alerts" {
value = data.scaleway_cockpit_preconfigured_alert.all.alerts
}
```

Run `terraform apply` and review the output to see available alerts.

#### Step 2: Select Specific Alerts

Choose the alerts you want to enable:

```terraform
resource "scaleway_cockpit_alert_manager" "main" {
project_id = scaleway_account_project.project.id

# Enable specific alerts by product/family
preconfigured_alert_ids = [
for alert in data.scaleway_cockpit_preconfigured_alert.all.alerts :
alert.preconfigured_rule_id
if contains(["PostgreSQL", "MySQL"], alert.product_name)
]

contact_points {
email = "alerts@example.com"
}
}
```

Or use specific alert IDs:

```terraform
resource "scaleway_cockpit_alert_manager" "main" {
project_id = scaleway_account_project.project.id

preconfigured_alert_ids = [
"6c6843af-1815-46df-9e52-6feafcf31fd7", # PostgreSQL Too Many Connections
"eb8a941e-698d-47d6-b62d-4b6c13f7b4b7", # MySQL Too Many Connections
]

contact_points {
email = "alerts@example.com"
}
}
```

## Filtering Alerts

### By Product Name

```terraform
preconfigured_alert_ids = [
for alert in data.scaleway_cockpit_preconfigured_alert.all.alerts :
alert.preconfigured_rule_id
if alert.product_name == "Kubernetes"
]
```

### By Product Family

```terraform
preconfigured_alert_ids = [
for alert in data.scaleway_cockpit_preconfigured_alert.all.alerts :
alert.preconfigured_rule_id
if alert.product_family == "Managed Databases"
]
```

### Multiple Criteria

```terraform
preconfigured_alert_ids = [
for alert in data.scaleway_cockpit_preconfigured_alert.all.alerts :
alert.preconfigured_rule_id
if alert.product_family == "Load Balancer" && alert.product_name == "LB"
]
```

## Important Notes

### Behavioral Changes

- **No automatic alerts**: Unlike `enable_managed_alerts = true`, the API will not automatically enable additional alerts
- **Explicit configuration**: You must explicitly list all alerts you want to enable
- **State accuracy**: Terraform state will only track alerts you've configured

### Compatibility

- The deprecated `enable_managed_alerts` field will be removed in a future major version
- Both fields can coexist during migration, but `preconfigured_alert_ids` takes precedence
- If neither field is specified, no preconfigured alerts will be enabled

## Troubleshooting

### "Insufficient permissions" Error

If you see permission errors when using the `scaleway_cockpit_preconfigured_alert` data source, ensure your IAM policy includes:

```json
{
"permission_sets": [
{
"name": "CockpitManager",
"permissions": [
"read:cockpit"
]
}
]
}
```

### Unexpected State Changes

If Terraform shows unexpected changes to `preconfigured_alert_ids`:

1. Verify the alert IDs still exist by querying the data source
2. Check that alerts are in `enabled` or `enabling` state
3. Ensure no manual changes were made outside Terraform

## Additional Resources

- [Cockpit Alert Manager Resource Documentation](../resources/cockpit_alert_manager.md)
- [Cockpit Preconfigured Alert Data Source Documentation](../data-sources/cockpit_preconfigured_alert.md)
- [Scaleway Cockpit Documentation](https://www.scaleway.com/en/docs/observability/cockpit/)


65 changes: 55 additions & 10 deletions docs/resources/cockpit_alert_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,48 @@ Refer to Cockpit's [product documentation](https://www.scaleway.com/en/docs/obse

## Example Usage

### Enable the alert manager and configure managed alerts
### Enable preconfigured alerts (Recommended)

The following commands allow you to:

- enable the alert manager in a Project named `tf_test_project`
- enable [managed alerts](https://www.scaleway.com/en/docs/observability/cockpit/concepts/#managed-alerts)
- set up [contact points](https://www.scaleway.com/en/docs/observability/cockpit/concepts/#contact-points) to receive alert notifications
Use preconfigured alerts to monitor your Scaleway resources with ready-to-use alert rules:

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

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

data "scaleway_cockpit_preconfigured_alert" "all" {
project_id = scaleway_cockpit.main.project_id
}

resource "scaleway_cockpit_alert_manager" "main" {
project_id = scaleway_cockpit.main.project_id

# Enable specific preconfigured alerts
preconfigured_alert_ids = [
for alert in data.scaleway_cockpit_preconfigured_alert.all.alerts :
alert.preconfigured_rule_id
if alert.product_name == "instance"
]

contact_points {
email = "alerts@example.com"
}
}
```

### Enable the alert manager with contact points

```terraform
resource "scaleway_account_project" "project" {
name = "tf_test_project"
}

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

contact_points {
email = "alert1@example.com"
Expand All @@ -40,13 +65,33 @@ resource "scaleway_cockpit_alert_manager" "alert_manager" {
}
```

### Legacy: Enable managed alerts (Deprecated)

~> **Deprecated:** The `enable_managed_alerts` field is deprecated. Use `preconfigured_alert_ids` instead.

```terraform
resource "scaleway_account_project" "project" {
name = "tf_test_project"
}

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

contact_points {
email = "alert@example.com"
}
}
```


## Argument Reference

This section lists the arguments that are supported:

- `enable_managed_alerts` - (Optional, Boolean) Specifies whether the alert manager should be enabled. Defaults to true.
- `contact_points` - (Optional, List of Map) A list of contact points with email addresses that will receive alerts. Each map should contain a single key email.
- `preconfigured_alert_ids` - (Optional, Set of String) A set of preconfigured alert rule IDs to enable explicitly. Use the [`scaleway_cockpit_preconfigured_alert`](../data-sources/cockpit_preconfigured_alert.md) data source to list available alerts.
- `enable_managed_alerts` - **Deprecated** (Optional, Boolean) Use `preconfigured_alert_ids` instead. This field will be removed in a future version. When set to `true`, it enables *all* preconfigured alerts for the project. You cannot filter or disable individual alerts with this legacy flag.
- `contact_points` - (Optional, List of Map) A list of contact points with email addresses that will receive alerts. Each map should contain a single key `email`.
- `project_id` - (Defaults to the Project ID specified in the [provider configuration](../index.md#project_id)) The ID of the Project the Cockpit is associated with.
- `region` - (Defaults to the region specified in the [provider configuration](../index.md#arguments-reference)) The [region](../guides/regions_and_zones.md#regions) where the [alert manager](https://www.scaleway.com/en/docs/observability/cockpit/concepts/#alert-manager) should be enabled.

Expand Down
Loading
Loading