azurerm_metric_alertrule
Manages a metric-based alert rule in Azure Monitor.
Example Usage (CPU Percentage of a virtual machine)
resource "azurerm_metric_alertrule" "test" { name = "${azurerm_virtual_machine.test.name}-cpu" resource_group_name = "${azurerm_resource_group.test.name}" location = "${azurerm_resource_group.test.location}" description = "An alert rule to watch the metric Percentage CPU" enabled = true resource_id = "${azurerm_virtual_machine.test.id}" metric_name = "Percentage CPU" operator = "GreaterThan" threshold = 75 aggregation = "Average" period = "PT5M" email_action { send_to_service_owners = false custom_emails = [ "[email protected]", ] } webhook_action { service_uri = "https://example.com/some-url" properties = { severity = "incredible" acceptance_test = "true" } } }
Example Usage (Storage usage of a SQL Database)
resource "azurerm_metric_alertrule" "test" { name = "${azurerm_sql_database.test.name}-storage" resource_group_name = "${azurerm_resource_group.test.name}" location = "${azurerm_resource_group.test.location}" description = "An alert rule to watch the metric Storage" enabled = true resource_id = "${azurerm_sql_database.test.id}" metric_name = "storage" operator = "GreaterThan" threshold = 1073741824 aggregation = "Maximum" period = "PT10M" email_action { send_to_service_owners = false custom_emails = [ "[email protected]", ] } webhook_action { service_uri = "https://example.com/some-url" properties = { severity = "incredible" acceptance_test = "true" } } }
Argument Reference
The following arguments are supported:
-
name
- (Required) Specifies the name of the alert rule. Changing this forces a new resource to be created. -
resource_group_name
- (Required) The name of the resource group in which to create the alert rule. Changing this forces a new resource to be created. -
location
- (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. -
description
- (Optional) A verbose description of the alert rule that will be included in the alert email. -
enabled
- (Optional) Iftrue
, the alert rule is enabled. Defaults totrue
.
-
resource_id
- (Required) The ID of the resource monitored by the alert rule. -
metric_name
- (Required) The metric that defines what the rule monitors.
For a comprehensive reference of supported
metric_name
values for types ofresource
refer to Supported metrics with Azure Monitor in the Azure documentation. In the referred table, the column "Metric" corresponds to supported values formetric_name
.
-
operator
- (Required) The operator used to compare the metric data and the threshold. Possible values areGreaterThan
,GreaterThanOrEqual
,LessThan
, andLessThanOrEqual
. -
threshold
- (Required) The threshold value that activates the alert. -
period
- (Required) The period of time formatted in ISO 8601 duration format that is used to monitor the alert activity based on the threshold. The period must be between 5 minutes and 1 day. -
aggregation
- (Required) Defines how the metric data is combined over time. Possible values areAverage
,Minimum
,Maximum
,Total
, andLast
.
-
email_action
- (Optional) Aemail_action
block as defined below. -
webhook_action
- (Optional) Awebhook_action
block as defined below. -
tags
- (Optional) A mapping of tags to assign to the resource. Changing this forces a new resource to be created.
email_action
supports the following:
-
send_to_service_owners
- (Optional) Iftrue
, the administrators (service and co-administrators) of the subscription are notified when the alert is triggered. Defaults tofalse
. -
custom_emails
- (Optional) A list of email addresses to be notified when the alert is triggered.
webhook_action
supports the following:
-
service_uri
- (Required) The service uri of the webhook to POST the notification when the alert is triggered. -
properties
- (Optional) A dictionary of custom properties to include with the webhook POST operation payload.
Attributes Reference
The following attributes are exported:
-
id
- The ID of the alert rule.
Import
Metric Alert Rules can be imported using the resource id
, e.g.
terraform import azurerm_metric_alertrule.alertrule1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/microsoft.insights/alertrules/alertrule1
© 2018 HashiCorpLicensed under the MPL 2.0 License.
https://www.terraform.io/docs/providers/azurerm/r/metric_alertrule.html