Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_monitor_activity_log_alert: support properties.recommendationType #7458

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,36 @@ func resourceArmMonitorActivityLogAlert() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"recommendation_category": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"Cost",
"Reliability",
"OperationalExcellence",
"Performance",
},
false,
),
ConflictsWith: []string{"criteria.0.recommendation_type"},
},
"recommendation_impact": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"High",
"Medium",
"Low",
},
false,
),
ConflictsWith: []string{"criteria.0.recommendation_type"},
},
"recommendation_type": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"criteria.0.recommendation_category", "criteria.0.recommendation_impact"},
},
},
},
},
Expand Down Expand Up @@ -348,6 +378,26 @@ func expandMonitorActivityLogAlertCriteria(input []interface{}) *insights.Activi
Equals: utils.String(subStatus),
})
}
if recommendationType := v["recommendation_type"].(string); recommendationType != "" {
conditions = append(conditions, insights.ActivityLogAlertLeafCondition{
Field: utils.String("properties.recommendationType"),
Equals: utils.String(recommendationType),
})
}

if recommendationCategory := v["recommendation_category"].(string); recommendationCategory != "" {
conditions = append(conditions, insights.ActivityLogAlertLeafCondition{
Field: utils.String("properties.recommendationCategory"),
Equals: utils.String(recommendationCategory),
})
}

if recommendationImpact := v["recommendation_impact"].(string); recommendationImpact != "" {
conditions = append(conditions, insights.ActivityLogAlertLeafCondition{
Field: utils.String("properties.recommendationImpact"),
Equals: utils.String(recommendationImpact),
})
}

return &insights.ActivityLogAlertAllOfCondition{
AllOf: &conditions,
Expand Down Expand Up @@ -397,6 +447,12 @@ func flattenMonitorActivityLogAlertCriteria(input *insights.ActivityLogAlertAllO
result["resource_id"] = *condition.Equals
case "substatus":
result["sub_status"] = *condition.Equals
case "properties.recommendationtype":
result["recommendation_type"] = *condition.Equals
case "properties.recommendationcategory":
result["recommendation_category"] = *condition.Equals
case "properties.recommendationimpact":
result["recommendation_impact"] = *condition.Equals
case "caller", "category", "level", "status":
result[*condition.Field] = *condition.Equals
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ func TestAccAzureRMMonitorActivityLogAlert_complete(t *testing.T) {
resource.TestCheckResourceAttr(data.ResourceName, "criteria.0.resource_type", "Microsoft.Storage/storageAccounts"),
resource.TestCheckResourceAttrSet(data.ResourceName, "criteria.0.resource_group"),
resource.TestCheckResourceAttrSet(data.ResourceName, "criteria.0.resource_id"),
resource.TestCheckResourceAttr(data.ResourceName, "criteria.0.caller", "[email protected]"),
resource.TestCheckResourceAttr(data.ResourceName, "criteria.0.level", "Error"),
resource.TestCheckResourceAttr(data.ResourceName, "criteria.0.status", "Failed"),
resource.TestCheckResourceAttr(data.ResourceName, "action.#", "2"),
),
},
Expand Down Expand Up @@ -154,9 +151,6 @@ func TestAccAzureRMMonitorActivityLogAlert_basicAndCompleteUpdate(t *testing.T)
resource.TestCheckResourceAttr(data.ResourceName, "criteria.0.resource_type", "Microsoft.Storage/storageAccounts"),
resource.TestCheckResourceAttrSet(data.ResourceName, "criteria.0.resource_group"),
resource.TestCheckResourceAttrSet(data.ResourceName, "criteria.0.resource_id"),
resource.TestCheckResourceAttr(data.ResourceName, "criteria.0.caller", "[email protected]"),
resource.TestCheckResourceAttr(data.ResourceName, "criteria.0.level", "Error"),
resource.TestCheckResourceAttr(data.ResourceName, "criteria.0.status", "Failed"),
resource.TestCheckResourceAttr(data.ResourceName, "action.#", "2"),
),
},
Expand Down Expand Up @@ -306,15 +300,14 @@ resource "azurerm_monitor_activity_log_alert" "test" {
]

criteria {
operation_name = "Microsoft.Storage/storageAccounts/write"
category = "Recommendation"
resource_provider = "Microsoft.Storage"
resource_type = "Microsoft.Storage/storageAccounts"
resource_group = azurerm_resource_group.test.name
resource_id = azurerm_storage_account.test.id
caller = "[email protected]"
level = "Error"
status = "Failed"
operation_name = "Microsoft.Storage/storageAccounts/write"
category = "Recommendation"
resource_provider = "Microsoft.Storage"
resource_type = "Microsoft.Storage/storageAccounts"
resource_group = azurerm_resource_group.test.name
resource_id = azurerm_storage_account.test.id
recommendation_category = "OperationalExcellence"
recommendation_impact = "High"
}

action {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/monitor_activity_log_alert.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ A `criteria` block supports the following:
* `level` - (Optional) The severity level of the event. Possible values are `Verbose`, `Informational`, `Warning`, `Error`, and `Critical`.
* `status` - (Optional) The status of the event. For example, `Started`, `Failed`, or `Succeeded`.
* `sub_status` - (Optional) The sub status of the event.
* `recommendation_type` - (Optional) The recommendation type of the event. It is only allowed when `category` is `Recommendation`.
* `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`.
* `recommendation_impact` - (Optional) The recommendation impact of the event. Possible values are `High`, `Medium` and `Low`. It is only allowed when `category` is `Recommendation`.


## Attributes Reference

Expand Down