Skip to content

Commit cd2225f

Browse files
authored
TPT-4302: Support ACLP alert definition additonal fields and entities (#2334)
* init * add doc * add doc * clean up * add monitoralertdefinitions test * rm deprecated fields * rm channel_ids from read path * update scope
1 parent 7b4ce65 commit cd2225f

20 files changed

Lines changed: 547 additions & 113 deletions

docs/data-sources/monitor_alert_definition.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,26 @@ In addition to all arguments above, the following attributes are exported:
4141
* [`rule_criteria`](#rule_criteria) - The criteria expression for the alert.
4242
* [`trigger_conditions`](#trigger_conditions) - The conditions that need to be met to send a notification for the alert.
4343
* `description` - A description for the alert definition.
44-
* `entity_ids` - A list of entity IDs to associate with the alert definition.
4544
* `status` - The status of the alert definition.
4645
* `type` - The type of alert. This can be either user for an alert specific to the current user, or system for one that applies to all users on your account.
47-
* `has_more_resources` - Whether there are additional entity_ids associated with the alert for which the user doesn't have at least read-only access.
4846
* `created` - The date and time the alert definition was created.
4947
* `updated` - The date and time the alert definition was last updated.
5048
* `created_by` - For a user alert definition, this is the user on your account that created it. For a system alert definition, this is returned as system.
5149
* `updated_by` - For a user alert definition, this is the user on your account that last updated it. For a system alert definition, this is returned as system. If it hasn't been updated, this value is the same as created_by.
5250
* `class` - "The plan type for the Managed Database cluster, either shared or dedicated. This only applies to a system alert for a service_type of dbaas (Managed Databases). For user alerts for dbaas, this is returned as null.",
51+
* `scope` - The scope of the alert definition. Possible values: `account`, `entity`, `region`.
52+
* `regions` - The regions the alert definition applies to. Only used for region-scoped alerts.
53+
* [`entities`](#entities) - Entity metadata for the alert definition.
5354
* [`alert_channels`](#alert_channels) - A list of alert channel objects associated with the alert definition.
5455

56+
### entities
57+
58+
The following attributes are exported in the `entities` block:
59+
60+
* `url` - The URL to list entities associated with the alert definition.
61+
* `count` - The number of entities associated with the alert definition.
62+
* `has_more_resources` - Whether there are additional entities associated with the alert.
63+
5564
### rule_criteria
5665

5766
The following arguments are supported in the `rule_criteria` specification block:
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
page_title: "Linode: linode_monitor_alert_definition_entities"
3+
description: |-
4+
Retrieves entities associated with a Monitor Alert Definition.
5+
---
6+
7+
# linode\_monitor\_alert\_definition\_entities
8+
9+
Retrieves the entities associated with a specific Monitor Alert Definition.
10+
For more information, see the [Linode APIv4 docs](TODO). (**Note: v4beta only.**)
11+
12+
## Example Usage
13+
14+
Retrieve entities for a specific alert definition:
15+
16+
```terraform
17+
data "linode_monitor_alert_definition_entities" "test" {
18+
service_type = "dbaas"
19+
alert_id = 123
20+
}
21+
```
22+
23+
Retrieve entities filtered by type:
24+
25+
```terraform
26+
data "linode_monitor_alert_definition_entities" "test" {
27+
service_type = "dbaas"
28+
alert_id = 123
29+
30+
filter {
31+
name = "type"
32+
values = ["dbaas"]
33+
}
34+
}
35+
```
36+
37+
## Argument Reference
38+
39+
The following arguments are supported:
40+
41+
* `service_type` - (Required) The service type for the alert definition (e.g., `dbaas`).
42+
43+
* `alert_id` - (Required) The unique identifier for the alert definition.
44+
45+
* [`filter`](#filter) - (Optional) A set of filters used to select entities that meet certain requirements.
46+
47+
### Filter
48+
49+
* `name` - (Required) The name of the field to filter by. See the [Filterable Fields section](#filterable-fields) for a complete list of filterable fields.
50+
51+
* `values` - (Required) A list of values for the filter to allow. These values should all be in string form.
52+
53+
* `match_by` - (Optional) The method to match the field by. (`exact`, `regex`, `substring`; default `exact`)
54+
55+
## Attributes Reference
56+
57+
Each entity will be stored in the `entities` attribute and will export the following attributes:
58+
59+
* `id` - The unique identifier for this entity.
60+
61+
* `label` - The label of this entity.
62+
63+
* `url` - The URL for this entity.
64+
65+
* `type` - The type of this entity.
66+
67+
## Filterable Fields
68+
69+
* `id`
70+
71+
* `label`
72+
73+
* `type`
74+
75+
* `url`

docs/data-sources/monitor_alert_definitions.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,26 @@ Each alert definition will be stored in the `alert_definitions` attribute and wi
6161
* [`rule_criteria`](#rule_criteria) - The criteria expression for the alert.
6262
* [`trigger_conditions`](#trigger_conditions) - The conditions that need to be met to send a notification for the alert.
6363
* `description` - A description for the alert definition.
64-
* `entity_ids` - A list of entity IDs to associate with the alert definition.
6564
* `status` - The status of the alert definition.
6665
* `type` - The type of alert. This can be either user for an alert specific to the current user, or system for one that applies to all users on your account.
67-
* `has_more_resources` - Whether there are additional entity_ids associated with the alert for which the user doesn't have at least read-only access.
6866
* `created` - The date and time the alert definition was created.
6967
* `updated` - The date and time the alert definition was last updated.
7068
* `created_by` - For a user alert definition, this is the user on your account that created it. For a system alert definition, this is returned as system.
7169
* `updated_by` - For a user alert definition, this is the user on your account that last updated it. For a system alert definition, this is returned as system. If it hasn't been updated, this value is the same as created_by.
7270
* `class` - "The plan type for the Managed Database cluster, either shared or dedicated. This only applies to a system alert for a service_type of dbaas (Managed Databases). For user alerts for dbaas, this is returned as null.",
71+
* `scope` - The scope of the alert definition. Possible values: `account`, `entity`, `region`.
72+
* `regions` - The regions the alert definition applies to. Only used for region-scoped alerts.
73+
* [`entities`](#entities) - Entity metadata for the alert definition.
7374
* [`alert_channels`](#alert_channels) - A list of alert channel objects associated with the alert definition.
7475

76+
### entities
77+
78+
The following attributes are exported in the `entities` block:
79+
80+
* `url` - The URL to list entities associated with the alert definition.
81+
* `count` - The number of entities associated with the alert definition.
82+
* `has_more_resources` - Whether there are additional entities associated with the alert.
83+
7584
### rule_criteria
7685

7786
The following arguments are supported in the `rule_criteria` specification block:

docs/resources/monitor_alert_definition.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ The following arguments are supported:
6262
* `description` - (Optional) A description for the alert definition.
6363
* `entity_ids` - (Optional) A list of entity IDs to associate with the alert definition.
6464
* `status` - (Optional) The status of the alert definition.
65+
* `scope` - (Optional) The scope of the alert definition. Allowed values: `account`, `entity`, `region`. Defaults to `entity`.
66+
* `regions` - (Optional) The regions the alert definition applies to. Only used for region-scoped alerts.
6567
* `wait_for` - (Optional) Whether to wait for the alert definition to be ready before completing the resource creation.
6668

6769
### rule_criteria
@@ -106,14 +108,22 @@ In addition to all arguments above, the following attributes are exported:
106108

107109
* `id` - The unique identifier assigned to the alert definition.
108110
* `type` - The type of alert. This can be either user for an alert specific to the current user, or system for one that applies to all users on your account.
109-
* `has_more_resources` - Whether there are additional entity_ids associated with the alert for which the user doesn't have at least read-only access.
110111
* `created` - The date and time the alert definition was created.
111112
* `updated` - The date and time the alert definition was last updated.
112113
* `created_by` - For a user alert definition, this is the user on your account that created it. For a system alert definition, this is returned as system.
113114
* `updated_by` - For a user alert definition, this is the user on your account that last updated it. For a system alert definition, this is returned as system. If it hasn't been updated, this value is the same as created_by.
114115
* `class` - "The plan type for the Managed Database cluster, either shared or dedicated. This only applies to a system alert for a service_type of dbaas (Managed Databases). For user alerts for dbaas, this is returned as null.",
116+
* [`entities`](#entities) - Entity metadata for the alert definition.
115117
* [`alert_channels`](#alert_channels) - A list of alert channel objects associated with the alert definition.
116118

119+
### entities
120+
121+
The following attributes are exported in the `entities` block:
122+
123+
* `url` - The URL to list entities associated with the alert definition.
124+
* `count` - The number of entities associated with the alert definition.
125+
* `has_more_resources` - Whether there are additional entities associated with the alert.
126+
117127
### alert_channels
118128

119129
The following attributes are exported in each `alert_channels` block:

linode/framework_provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import (
6464
"github.com/linode/terraform-provider-linode/v3/linode/maintenancepolicies"
6565
"github.com/linode/terraform-provider-linode/v3/linode/monitoralertchannels"
6666
"github.com/linode/terraform-provider-linode/v3/linode/monitoralertdefinition"
67+
"github.com/linode/terraform-provider-linode/v3/linode/monitoralertdefinitionentities"
6768
"github.com/linode/terraform-provider-linode/v3/linode/monitoralertdefinitions"
6869
"github.com/linode/terraform-provider-linode/v3/linode/nb"
6970
"github.com/linode/terraform-provider-linode/v3/linode/nbconfig"
@@ -380,6 +381,7 @@ func (p *FrameworkProvider) DataSources(ctx context.Context) []func() datasource
380381
consumerimagesharegroupimageshares.NewDataSource,
381382
monitoralertdefinition.NewDataSource,
382383
monitoralertdefinitions.NewDataSource,
384+
monitoralertdefinitionentities.NewDataSource,
383385
lkenodepool.NewDataSource,
384386
regionvpcavailability.NewDataSource,
385387
regionsvpcavailability.NewDataSource,

linode/monitoralertdefinition/datasource_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ func TestAccDataSourceAlertDefinition_basic(t *testing.T) {
3636
statecheck.ExpectKnownValue(resName, tfjsonpath.New("service_type"), knownvalue.NotNull()),
3737
statecheck.ExpectKnownValue(resName, tfjsonpath.New("description"), knownvalue.NotNull()),
3838
statecheck.ExpectKnownValue(resName, tfjsonpath.New("severity"), knownvalue.NotNull()),
39-
statecheck.ExpectKnownValue(resName, tfjsonpath.New("channel_ids"), knownvalue.NotNull()),
40-
statecheck.ExpectKnownValue(resName, tfjsonpath.New("entity_ids"), knownvalue.NotNull()),
4139
statecheck.ExpectKnownValue(resName, tfjsonpath.New("status"), knownvalue.NotNull()),
4240
statecheck.ExpectKnownValue(resName, tfjsonpath.New("type"), knownvalue.NotNull()),
43-
statecheck.ExpectKnownValue(resName, tfjsonpath.New("has_more_resources"), knownvalue.NotNull()),
4441
statecheck.ExpectKnownValue(resName, tfjsonpath.New("created"), knownvalue.NotNull()),
4542
statecheck.ExpectKnownValue(resName, tfjsonpath.New("updated"), knownvalue.NotNull()),
4643
statecheck.ExpectKnownValue(resName, tfjsonpath.New("created_by"), knownvalue.NotNull()),
4744
statecheck.ExpectKnownValue(resName, tfjsonpath.New("updated_by"), knownvalue.NotNull()),
4845
statecheck.ExpectKnownValue(resName, tfjsonpath.New("class"), knownvalue.NotNull()),
46+
statecheck.ExpectKnownValue(resName, tfjsonpath.New("scope"), knownvalue.NotNull()),
47+
statecheck.ExpectKnownValue(resName, tfjsonpath.New("regions"), knownvalue.NotNull()),
48+
statecheck.ExpectKnownValue(resName, tfjsonpath.New("entities"), knownvalue.NotNull()),
4949
statecheck.ExpectKnownValue(resName, tfjsonpath.New("alert_channels").AtSliceIndex(0).AtMapKey("id"), knownvalue.NotNull()),
5050
statecheck.ExpectKnownValue(resName, tfjsonpath.New("alert_channels").AtSliceIndex(0).AtMapKey("label"), knownvalue.NotNull()),
5151
statecheck.ExpectKnownValue(resName, tfjsonpath.New("alert_channels").AtSliceIndex(0).AtMapKey("type"), knownvalue.NotNull()),

linode/monitoralertdefinition/framework_datasource_schema.go

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,10 @@ var AlertDefinitionAttributes = map[string]schema.Attribute{
9595
Required: true,
9696
Description: "The Akamai Cloud Computing service being monitored.",
9797
},
98-
"channel_ids": schema.ListAttribute{
99-
ElementType: types.Int64Type,
100-
Computed: true,
101-
Description: "The identifiers for the alert channels to use for the alert.",
102-
},
10398
"description": schema.StringAttribute{
10499
Computed: true,
105100
Description: "An additional description for the alert definition.",
106101
},
107-
"entity_ids": schema.ListAttribute{
108-
ElementType: types.StringType,
109-
Computed: true,
110-
Description: "The id for each individual entity from a service_type.",
111-
},
112102
"label": schema.StringAttribute{
113103
Computed: true,
114104
Description: "The name of the alert definition.",
@@ -158,10 +148,6 @@ var AlertDefinitionAttributes = map[string]schema.Attribute{
158148
Computed: true,
159149
Description: "The type of alert.",
160150
},
161-
"has_more_resources": schema.BoolAttribute{
162-
Computed: true,
163-
Description: "Whether there are additional entity_ids associated with the alert.",
164-
},
165151
"alert_channels": schema.ListNestedAttribute{
166152
NestedObject: alertChannelDataSourceNestedObj,
167153
Computed: true,
@@ -189,4 +175,31 @@ var AlertDefinitionAttributes = map[string]schema.Attribute{
189175
Computed: true,
190176
Description: "Plan type for Managed Database clusters (shared or dedicated).",
191177
},
178+
"scope": schema.StringAttribute{
179+
Computed: true,
180+
Description: "The scope of the alert definition. Allowed values: account, entity, region.",
181+
},
182+
"regions": schema.ListAttribute{
183+
ElementType: types.StringType,
184+
Computed: true,
185+
Description: "The regions the alert definition applies to. Only used for region-scoped alerts.",
186+
},
187+
"entities": schema.SingleNestedAttribute{
188+
Attributes: map[string]schema.Attribute{
189+
"url": schema.StringAttribute{
190+
Computed: true,
191+
Description: "The URL to list entities associated with the alert definition.",
192+
},
193+
"count": schema.Int64Attribute{
194+
Computed: true,
195+
Description: "The number of entities associated with the alert definition.",
196+
},
197+
"has_more_resources": schema.BoolAttribute{
198+
Computed: true,
199+
Description: "Whether there are additional entities associated with the alert.",
200+
},
201+
},
202+
Computed: true,
203+
Description: "Entity metadata for the alert definition.",
204+
},
192205
}

0 commit comments

Comments
 (0)