Skip to content

Commit 16c702f

Browse files
Merge pull request #7458 from magodo/monitor_activity_log_alert_recommendation_type
azurerm_monitor_activity_log_alert: support `properties.recommendationType`
2 parents a20ceeb + 183f3e7 commit 16c702f

File tree

3 files changed

+68
-15
lines changed

3 files changed

+68
-15
lines changed

azurerm/internal/services/monitor/monitor_activity_log_alert_resource.go

+56
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,36 @@ func resourceArmMonitorActivityLogAlert() *schema.Resource {
123123
Type: schema.TypeString,
124124
Optional: true,
125125
},
126+
"recommendation_category": {
127+
Type: schema.TypeString,
128+
Optional: true,
129+
ValidateFunc: validation.StringInSlice([]string{
130+
"Cost",
131+
"Reliability",
132+
"OperationalExcellence",
133+
"Performance",
134+
},
135+
false,
136+
),
137+
ConflictsWith: []string{"criteria.0.recommendation_type"},
138+
},
139+
"recommendation_impact": {
140+
Type: schema.TypeString,
141+
Optional: true,
142+
ValidateFunc: validation.StringInSlice([]string{
143+
"High",
144+
"Medium",
145+
"Low",
146+
},
147+
false,
148+
),
149+
ConflictsWith: []string{"criteria.0.recommendation_type"},
150+
},
151+
"recommendation_type": {
152+
Type: schema.TypeString,
153+
Optional: true,
154+
ConflictsWith: []string{"criteria.0.recommendation_category", "criteria.0.recommendation_impact"},
155+
},
126156
},
127157
},
128158
},
@@ -348,6 +378,26 @@ func expandMonitorActivityLogAlertCriteria(input []interface{}) *insights.Activi
348378
Equals: utils.String(subStatus),
349379
})
350380
}
381+
if recommendationType := v["recommendation_type"].(string); recommendationType != "" {
382+
conditions = append(conditions, insights.ActivityLogAlertLeafCondition{
383+
Field: utils.String("properties.recommendationType"),
384+
Equals: utils.String(recommendationType),
385+
})
386+
}
387+
388+
if recommendationCategory := v["recommendation_category"].(string); recommendationCategory != "" {
389+
conditions = append(conditions, insights.ActivityLogAlertLeafCondition{
390+
Field: utils.String("properties.recommendationCategory"),
391+
Equals: utils.String(recommendationCategory),
392+
})
393+
}
394+
395+
if recommendationImpact := v["recommendation_impact"].(string); recommendationImpact != "" {
396+
conditions = append(conditions, insights.ActivityLogAlertLeafCondition{
397+
Field: utils.String("properties.recommendationImpact"),
398+
Equals: utils.String(recommendationImpact),
399+
})
400+
}
351401

352402
return &insights.ActivityLogAlertAllOfCondition{
353403
AllOf: &conditions,
@@ -397,6 +447,12 @@ func flattenMonitorActivityLogAlertCriteria(input *insights.ActivityLogAlertAllO
397447
result["resource_id"] = *condition.Equals
398448
case "substatus":
399449
result["sub_status"] = *condition.Equals
450+
case "properties.recommendationtype":
451+
result["recommendation_type"] = *condition.Equals
452+
case "properties.recommendationcategory":
453+
result["recommendation_category"] = *condition.Equals
454+
case "properties.recommendationimpact":
455+
result["recommendation_impact"] = *condition.Equals
400456
case "caller", "category", "level", "status":
401457
result[*condition.Field] = *condition.Equals
402458
}

azurerm/internal/services/monitor/tests/monitor_activity_log_alert_resource_test.go

+8-15
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ func TestAccAzureRMMonitorActivityLogAlert_complete(t *testing.T) {
105105
resource.TestCheckResourceAttr(data.ResourceName, "criteria.0.resource_type", "Microsoft.Storage/storageAccounts"),
106106
resource.TestCheckResourceAttrSet(data.ResourceName, "criteria.0.resource_group"),
107107
resource.TestCheckResourceAttrSet(data.ResourceName, "criteria.0.resource_id"),
108-
resource.TestCheckResourceAttr(data.ResourceName, "criteria.0.caller", "[email protected]"),
109-
resource.TestCheckResourceAttr(data.ResourceName, "criteria.0.level", "Error"),
110-
resource.TestCheckResourceAttr(data.ResourceName, "criteria.0.status", "Failed"),
111108
resource.TestCheckResourceAttr(data.ResourceName, "action.#", "2"),
112109
),
113110
},
@@ -154,9 +151,6 @@ func TestAccAzureRMMonitorActivityLogAlert_basicAndCompleteUpdate(t *testing.T)
154151
resource.TestCheckResourceAttr(data.ResourceName, "criteria.0.resource_type", "Microsoft.Storage/storageAccounts"),
155152
resource.TestCheckResourceAttrSet(data.ResourceName, "criteria.0.resource_group"),
156153
resource.TestCheckResourceAttrSet(data.ResourceName, "criteria.0.resource_id"),
157-
resource.TestCheckResourceAttr(data.ResourceName, "criteria.0.caller", "[email protected]"),
158-
resource.TestCheckResourceAttr(data.ResourceName, "criteria.0.level", "Error"),
159-
resource.TestCheckResourceAttr(data.ResourceName, "criteria.0.status", "Failed"),
160154
resource.TestCheckResourceAttr(data.ResourceName, "action.#", "2"),
161155
),
162156
},
@@ -306,15 +300,14 @@ resource "azurerm_monitor_activity_log_alert" "test" {
306300
]
307301
308302
criteria {
309-
operation_name = "Microsoft.Storage/storageAccounts/write"
310-
category = "Recommendation"
311-
resource_provider = "Microsoft.Storage"
312-
resource_type = "Microsoft.Storage/storageAccounts"
313-
resource_group = azurerm_resource_group.test.name
314-
resource_id = azurerm_storage_account.test.id
315-
caller = "[email protected]"
316-
level = "Error"
317-
status = "Failed"
303+
operation_name = "Microsoft.Storage/storageAccounts/write"
304+
category = "Recommendation"
305+
resource_provider = "Microsoft.Storage"
306+
resource_type = "Microsoft.Storage/storageAccounts"
307+
resource_group = azurerm_resource_group.test.name
308+
resource_id = azurerm_storage_account.test.id
309+
recommendation_category = "OperationalExcellence"
310+
recommendation_impact = "High"
318311
}
319312
320313
action {

website/docs/r/monitor_activity_log_alert.html.markdown

+4
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ A `criteria` block supports the following:
9393
* `level` - (Optional) The severity level of the event. Possible values are `Verbose`, `Informational`, `Warning`, `Error`, and `Critical`.
9494
* `status` - (Optional) The status of the event. For example, `Started`, `Failed`, or `Succeeded`.
9595
* `sub_status` - (Optional) The sub status of the event.
96+
* `recommendation_type` - (Optional) The recommendation type of the event. It is only allowed when `category` is `Recommendation`.
97+
* `recommendation_category` - (Optional) The recommendation category of the event. Possible values are `Cost`, `Reliability`, `OperationalExcellence` and `Performance`. It is only allowed when `category` is `Recommendation`.
98+
* `recommendation_impact` - (Optional) The recommendation impact of the event. Possible values are `High`, `Medium` and `Low`. It is only allowed when `category` is `Recommendation`.
99+
96100

97101
## Attributes Reference
98102

0 commit comments

Comments
 (0)