Skip to content

Commit a963535

Browse files
committed
feat(cockpit): add preconfigured_alert_ids field and deprecate enable_managed_alerts
1 parent d8c6184 commit a963535

File tree

11 files changed

+1176
-64
lines changed

11 files changed

+1176
-64
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
subcategory: "Cockpit"
3+
page_title: "Scaleway: scaleway_cockpit_preconfigured_alert"
4+
---
5+
6+
# Data Source: scaleway_cockpit_preconfigured_alert
7+
8+
Gets information about preconfigured alert rules available in Scaleway Cockpit.
9+
10+
Preconfigured alerts are ready-to-use alert rules that monitor common metrics for Scaleway services.
11+
You can enable these alerts in your Alert Manager using the `scaleway_cockpit_alert_manager` resource.
12+
13+
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).
14+
15+
## Example Usage
16+
17+
### Basic usage
18+
19+
```terraform
20+
data "scaleway_cockpit_preconfigured_alert" "main" {
21+
project_id = scaleway_account_project.project.id
22+
}
23+
24+
output "available_alerts" {
25+
value = data.scaleway_cockpit_preconfigured_alert.main.alerts
26+
}
27+
```
28+
29+
### Filter by status
30+
31+
```terraform
32+
data "scaleway_cockpit_preconfigured_alert" "enabled" {
33+
project_id = scaleway_account_project.project.id
34+
rule_status = "enabled"
35+
}
36+
37+
data "scaleway_cockpit_preconfigured_alert" "disabled" {
38+
project_id = scaleway_account_project.project.id
39+
rule_status = "disabled"
40+
}
41+
```
42+
43+
### Use with Alert Manager
44+
45+
```terraform
46+
resource "scaleway_account_project" "project" {
47+
name = "my-observability-project"
48+
}
49+
50+
resource "scaleway_cockpit" "main" {
51+
project_id = scaleway_account_project.project.id
52+
}
53+
54+
data "scaleway_cockpit_preconfigured_alert" "all" {
55+
project_id = scaleway_cockpit.main.project_id
56+
}
57+
58+
resource "scaleway_cockpit_alert_manager" "main" {
59+
project_id = scaleway_cockpit.main.project_id
60+
61+
# Enable specific alerts by their preconfigured_rule_id
62+
preconfigured_alert_ids = [
63+
for alert in data.scaleway_cockpit_preconfigured_alert.all.alerts :
64+
alert.preconfigured_rule_id
65+
if alert.product_name == "instance" && alert.rule_status == "disabled"
66+
]
67+
68+
contact_points {
69+
70+
}
71+
}
72+
```
73+
74+
## Argument Reference
75+
76+
- `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.
77+
- `region` - (Optional, defaults to provider region) The region in which the alerts exist.
78+
- `data_source_id` - (Optional) Filter alerts by data source ID.
79+
- `rule_status` - (Optional) Filter alerts by rule status. Valid values are `enabled` or `disabled`.
80+
81+
## Attributes Reference
82+
83+
In addition to all arguments above, the following attributes are exported:
84+
85+
- `id` - The ID of the resource (project ID with region).
86+
- `alerts` - List of preconfigured alerts. Each alert contains:
87+
- `name` - Name of the alert rule.
88+
- `rule` - PromQL expression defining the alert condition.
89+
- `duration` - Duration for which the condition must be true before the alert fires (e.g., "5m").
90+
- `rule_status` - Status of the alert rule (`enabled`, `disabled`, `enabling`, `disabling`).
91+
- `state` - Current state of the alert (`inactive`, `pending`, `firing`).
92+
- `annotations` - Map of annotations attached to the alert.
93+
- `preconfigured_rule_id` - Unique identifier of the preconfigured rule. Use this ID in `scaleway_cockpit_alert_manager` resource.
94+
- `display_name` - Human-readable name of the alert.
95+
- `display_description` - Human-readable description of the alert.
96+
- `product_name` - Scaleway product associated with the alert (e.g., "instance", "rdb", "kubernetes").
97+
- `product_family` - Family of the product (e.g., "compute", "storage", "network").
98+
- `data_source_id` - ID of the data source containing the alert rule.
99+
100+
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
---
2+
page_title: "Cockpit Alert Manager Migration Guide"
3+
---
4+
5+
# Cockpit Alert Manager Migration Guide
6+
7+
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.
8+
9+
## Background
10+
11+
The `enable_managed_alerts` field is being deprecated in favor of a more flexible approach using `preconfigured_alert_ids`. This change provides:
12+
13+
- **Granular control**: Select specific alerts instead of enabling all managed alerts
14+
- **Better visibility**: Explicitly declare which alerts are enabled in your Terraform configuration
15+
- **Improved state management**: Terraform accurately tracks which alerts are active
16+
17+
## Migration Steps
18+
19+
### Before Migration (Deprecated)
20+
21+
```terraform
22+
resource "scaleway_cockpit_alert_manager" "main" {
23+
project_id = scaleway_account_project.project.id
24+
enable_managed_alerts = true
25+
26+
contact_points {
27+
28+
}
29+
}
30+
```
31+
32+
### After Migration (Recommended)
33+
34+
#### Step 1: List Available Preconfigured Alerts
35+
36+
Use the data source to discover available alerts:
37+
38+
```terraform
39+
data "scaleway_cockpit_preconfigured_alert" "all" {
40+
project_id = scaleway_account_project.project.id
41+
}
42+
43+
output "available_alerts" {
44+
value = data.scaleway_cockpit_preconfigured_alert.all.alerts
45+
}
46+
```
47+
48+
Run `terraform apply` and review the output to see available alerts.
49+
50+
#### Step 2: Select Specific Alerts
51+
52+
Choose the alerts you want to enable:
53+
54+
```terraform
55+
resource "scaleway_cockpit_alert_manager" "main" {
56+
project_id = scaleway_account_project.project.id
57+
58+
# Enable specific alerts by product/family
59+
preconfigured_alert_ids = [
60+
for alert in data.scaleway_cockpit_preconfigured_alert.all.alerts :
61+
alert.preconfigured_rule_id
62+
if contains(["PostgreSQL", "MySQL"], alert.product_name)
63+
]
64+
65+
contact_points {
66+
67+
}
68+
}
69+
```
70+
71+
Or use specific alert IDs:
72+
73+
```terraform
74+
resource "scaleway_cockpit_alert_manager" "main" {
75+
project_id = scaleway_account_project.project.id
76+
77+
preconfigured_alert_ids = [
78+
"6c6843af-1815-46df-9e52-6feafcf31fd7", # PostgreSQL Too Many Connections
79+
"eb8a941e-698d-47d6-b62d-4b6c13f7b4b7", # MySQL Too Many Connections
80+
]
81+
82+
contact_points {
83+
84+
}
85+
}
86+
```
87+
88+
## Filtering Alerts
89+
90+
### By Product Name
91+
92+
```terraform
93+
preconfigured_alert_ids = [
94+
for alert in data.scaleway_cockpit_preconfigured_alert.all.alerts :
95+
alert.preconfigured_rule_id
96+
if alert.product_name == "Kubernetes"
97+
]
98+
```
99+
100+
### By Product Family
101+
102+
```terraform
103+
preconfigured_alert_ids = [
104+
for alert in data.scaleway_cockpit_preconfigured_alert.all.alerts :
105+
alert.preconfigured_rule_id
106+
if alert.product_family == "Managed Databases"
107+
]
108+
```
109+
110+
### Multiple Criteria
111+
112+
```terraform
113+
preconfigured_alert_ids = [
114+
for alert in data.scaleway_cockpit_preconfigured_alert.all.alerts :
115+
alert.preconfigured_rule_id
116+
if alert.product_family == "Load Balancer" && alert.product_name == "LB"
117+
]
118+
```
119+
120+
## Important Notes
121+
122+
### Behavioral Changes
123+
124+
- **No automatic alerts**: Unlike `enable_managed_alerts = true`, the API will not automatically enable additional alerts
125+
- **Explicit configuration**: You must explicitly list all alerts you want to enable
126+
- **State accuracy**: Terraform state will only track alerts you've configured
127+
128+
### Compatibility
129+
130+
- The deprecated `enable_managed_alerts` field will be removed in a future major version
131+
- Both fields can coexist during migration, but `preconfigured_alert_ids` takes precedence
132+
- If neither field is specified, no preconfigured alerts will be enabled
133+
134+
## Troubleshooting
135+
136+
### "Insufficient permissions" Error
137+
138+
If you see permission errors when using the `scaleway_cockpit_preconfigured_alert` data source, ensure your IAM policy includes:
139+
140+
```json
141+
{
142+
"permission_sets": [
143+
{
144+
"name": "CockpitManager",
145+
"permissions": [
146+
"read:cockpit"
147+
]
148+
}
149+
]
150+
}
151+
```
152+
153+
### Unexpected State Changes
154+
155+
If Terraform shows unexpected changes to `preconfigured_alert_ids`:
156+
157+
1. Verify the alert IDs still exist by querying the data source
158+
2. Check that alerts are in `enabled` or `enabling` state
159+
3. Ensure no manual changes were made outside Terraform
160+
161+
## Additional Resources
162+
163+
- [Cockpit Alert Manager Resource Documentation](../resources/cockpit_alert_manager.md)
164+
- [Cockpit Preconfigured Alert Data Source Documentation](../data-sources/cockpit_preconfigured_alert.md)
165+
- [Scaleway Cockpit Documentation](https://www.scaleway.com/en/docs/observability/cockpit/)
166+

docs/resources/cockpit_alert_manager.md

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,48 @@ Refer to Cockpit's [product documentation](https://www.scaleway.com/en/docs/obse
1212

1313
## Example Usage
1414

15-
### Enable the alert manager and configure managed alerts
15+
### Enable preconfigured alerts (Recommended)
1616

17-
The following commands allow you to:
18-
19-
- enable the alert manager in a Project named `tf_test_project`
20-
- enable [managed alerts](https://www.scaleway.com/en/docs/observability/cockpit/concepts/#managed-alerts)
21-
- set up [contact points](https://www.scaleway.com/en/docs/observability/cockpit/concepts/#contact-points) to receive alert notifications
17+
Use preconfigured alerts to monitor your Scaleway resources with ready-to-use alert rules:
2218

2319
```terraform
20+
resource "scaleway_account_project" "project" {
21+
name = "my-observability-project"
22+
}
23+
24+
resource "scaleway_cockpit" "main" {
25+
project_id = scaleway_account_project.project.id
26+
}
27+
28+
data "scaleway_cockpit_preconfigured_alert" "all" {
29+
project_id = scaleway_cockpit.main.project_id
30+
}
31+
32+
resource "scaleway_cockpit_alert_manager" "main" {
33+
project_id = scaleway_cockpit.main.project_id
34+
35+
# Enable specific preconfigured alerts
36+
preconfigured_alert_ids = [
37+
for alert in data.scaleway_cockpit_preconfigured_alert.all.alerts :
38+
alert.preconfigured_rule_id
39+
if alert.product_name == "instance"
40+
]
2441
42+
contact_points {
43+
44+
}
45+
}
46+
```
47+
48+
### Enable the alert manager with contact points
49+
50+
```terraform
2551
resource "scaleway_account_project" "project" {
2652
name = "tf_test_project"
2753
}
2854
2955
resource "scaleway_cockpit_alert_manager" "alert_manager" {
30-
project_id = scaleway_account_project.project.id
31-
enable_managed_alerts = true
56+
project_id = scaleway_account_project.project.id
3257
3358
contact_points {
3459
@@ -40,13 +65,33 @@ resource "scaleway_cockpit_alert_manager" "alert_manager" {
4065
}
4166
```
4267

68+
### Legacy: Enable managed alerts (Deprecated)
69+
70+
~> **Deprecated:** The `enable_managed_alerts` field is deprecated. Use `preconfigured_alert_ids` instead.
71+
72+
```terraform
73+
resource "scaleway_account_project" "project" {
74+
name = "tf_test_project"
75+
}
76+
77+
resource "scaleway_cockpit_alert_manager" "alert_manager" {
78+
project_id = scaleway_account_project.project.id
79+
enable_managed_alerts = true
80+
81+
contact_points {
82+
83+
}
84+
}
85+
```
86+
4387

4488
## Argument Reference
4589

4690
This section lists the arguments that are supported:
4791

48-
- `enable_managed_alerts` - (Optional, Boolean) Specifies whether the alert manager should be enabled. Defaults to true.
49-
- `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.
92+
- `preconfigured_alert_ids` - (Optional, Set of String) A set of preconfigured alert rule IDs to enable. Use the [`scaleway_cockpit_preconfigured_alert`](../data-sources/cockpit_preconfigured_alert.md) data source to list available alerts.
93+
- `enable_managed_alerts` - **Deprecated** (Optional, Boolean) Use `preconfigured_alert_ids` instead. This field will be removed in a future version.
94+
- `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`.
5095
- `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.
5196
- `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.
5297

0 commit comments

Comments
 (0)