Skip to content
Draft
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
100 changes: 100 additions & 0 deletions docs/data-sources/cockpit_preconfigured_alert.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
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 = "[email protected]"
}
}
```

## 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.


166 changes: 166 additions & 0 deletions docs/guides/migration_guide_cockpit_alert_manager.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
---
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 = "[email protected]"
}
}
```

### 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 = "[email protected]"
}
}
```

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 = "[email protected]"
}
}
```

## 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/)

66 changes: 56 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 = "[email protected]"
}
}
```

### 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 = "[email protected]"
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 = "[email protected]"
}
}
```


## 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.
- `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 All @@ -55,6 +100,7 @@ This section lists the arguments that are supported:
In addition to all arguments above, the following attributes are exported:

- `alert_manager_url` - The URL of the alert manager.
- `default_preconfigured_alert_ids` - (Set of String) A set of preconfigured alert rule IDs that are enabled automatically by the API when the alert manager is activated. This is a computed field that shows which alerts the API enables by default.


## Import
Expand Down
Loading
Loading