Skip to content

Commit

Permalink
Merge pull request #7458 from magodo/monitor_activity_log_alert_recom…
Browse files Browse the repository at this point in the history
…mendation_type

azurerm_monitor_activity_log_alert: support `properties.recommendationType`
  • Loading branch information
tombuildsstuff committed Jun 25, 2020
2 parents a20ceeb + 183f3e7 commit 16c702f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 15 deletions.
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
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", "user@example.com"),
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", "user@example.com"),
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 = "user@example.com"
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
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

0 comments on commit 16c702f

Please sign in to comment.