» azurerm_monitor_autoscale_setting
Manages a AutoScale Setting which can be applied to Virtual Machine Scale Sets, App Services and other scalable resources.
» Example Usage
resource "azurerm_resource_group" "test" {
name = "autoscalingTest"
location = "West US"
}
resource "azurerm_virtual_machine_scale_set" "test" {
# ...
}
resource "azurerm_monitor_autoscale_setting" "test" {
name = "myAutoscaleSetting"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
target_resource_id = "${azurerm_virtual_machine_scale_set.test.id}"
profile {
name = "defaultProfile"
capacity {
default = 1
minimum = 1
maximum = 10
}
rule {
metric_trigger {
metric_name = "Percentage CPU"
metric_resource_id = "${azurerm_virtual_machine_scale_set.test.id}"
time_grain = "PT1M"
statistic = "Average"
time_window = "PT5M"
time_aggregation = "Average"
operator = "GreaterThan"
threshold = 75
}
scale_action {
direction = "Increase"
type = "ChangeCount"
value = "1"
cooldown = "PT1M"
}
}
rule {
metric_trigger {
metric_name = "Percentage CPU"
metric_resource_id = "${azurerm_virtual_machine_scale_set.test.id}"
time_grain = "PT1M"
statistic = "Average"
time_window = "PT5M"
time_aggregation = "Average"
operator = "LessThan"
threshold = 25
}
scale_action {
direction = "Decrease"
type = "ChangeCount"
value = "1"
cooldown = "PT1M"
}
}
}
notification {
email {
send_to_subscription_administrator = true
send_to_subscription_co_administrator = true
custom_emails = ["admin@contoso.com"]
}
}
}
» Example Usage (repeating on weekends)
resource "azurerm_resource_group" "test" {
name = "autoscalingTest"
location = "West US"
}
resource "azurerm_virtual_machine_scale_set" "test" {
# ...
}
resource "azurerm_monitor_autoscale_setting" "test" {
name = "myAutoscaleSetting"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
target_resource_id = "${azurerm_virtual_machine_scale_set.test.id}"
profile {
name = "Weekends"
capacity {
default = 1
minimum = 1
maximum = 10
}
rule {
metric_trigger {
metric_name = "Percentage CPU"
metric_resource_id = "${azurerm_virtual_machine_scale_set.test.id}"
time_grain = "PT1M"
statistic = "Average"
time_window = "PT5M"
time_aggregation = "Average"
operator = "GreaterThan"
threshold = 90
}
scale_action {
direction = "Increase"
type = "ChangeCount"
value = "2"
cooldown = "PT1M"
}
}
rule {
metric_trigger {
metric_name = "Percentage CPU"
metric_resource_id = "${azurerm_virtual_machine_scale_set.test.id}"
time_grain = "PT1M"
statistic = "Average"
time_window = "PT5M"
time_aggregation = "Average"
operator = "LessThan"
threshold = 10
}
scale_action {
direction = "Decrease"
type = "ChangeCount"
value = "2"
cooldown = "PT1M"
}
}
recurrence {
frequency = "Week"
timezone = "Pacific Standard Time"
days = ["Saturday", "Sunday"]
hours = [12]
minutes = [0]
}
}
notification {
email {
send_to_subscription_administrator = true
send_to_subscription_co_administrator = true
custom_emails = ["admin@contoso.com"]
}
}
}
» Example Usage (for fixed dates)
resource "azurerm_resource_group" "test" {
name = "autoscalingTest"
location = "West US"
}
resource "azurerm_virtual_machine_scale_set" "test" {
# ...
}
resource "azurerm_monitor_autoscale_setting" "test" {
name = "myAutoscaleSetting"
enabled = true
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
target_resource_id = "${azurerm_virtual_machine_scale_set.test.id}"
profile {
name = "forJuly"
capacity {
default = 1
minimum = 1
maximum = 10
}
rule {
metric_trigger {
metric_name = "Percentage CPU"
metric_resource_id = "${azurerm_virtual_machine_scale_set.test.id}"
time_grain = "PT1M"
statistic = "Average"
time_window = "PT5M"
time_aggregation = "Average"
operator = "GreaterThan"
threshold = 90
}
scale_action {
direction = "Increase"
type = "ChangeCount"
value = "2"
cooldown = "PT1M"
}
}
rule {
metric_trigger {
metric_name = "Percentage CPU"
metric_resource_id = "${azurerm_virtual_machine_scale_set.test.id}"
time_grain = "PT1M"
statistic = "Average"
time_window = "PT5M"
time_aggregation = "Average"
operator = "LessThan"
threshold = 10
}
scale_action {
direction = "Decrease"
type = "ChangeCount"
value = "2"
cooldown = "PT1M"
}
}
fixed_date {
timezone = "Pacific Standard Time"
start = "2020-07-01T00:00:00Z"
end = "2020-07-31T23:59:59Z"
}
}
notification {
email {
send_to_subscription_administrator = true
send_to_subscription_co_administrator = true
custom_emails = ["admin@contoso.com"]
}
}
}
» Argument Reference
The following arguments are supported:
-
name- (Required) The name of the AutoScale Setting. Changing this forces a new resource to be created. -
resource_group_name- (Required) The name of the Resource Group in the AutoScale Setting should be created. Changing this forces a new resource to be created. -
location- (Required) Specifies the supported Azure location where the AutoScale Setting should exist. Changing this forces a new resource to be created. -
profile- (Required) Specifies one or more (up to 20)profileblocks as defined below. -
target_resource_id- (Required) Specifies the resource ID of the resource that the autoscale setting should be added to. -
enabled- (Optional) Specifies whether automatic scaling is enabled for the target resource. Defaults totrue. -
notification- (Optional) Specifies anotificationblock as defined below. -
tags- (Optional) A mapping of tags to assign to the resource.
A profile block supports the following:
-
name- (Required) Specifies the name of the profile. -
capacity- (Required) Acapacityblock as defined below. -
rule- (Required) One or more (up to 10)ruleblocks as defined below. -
fixed_date- (Optional) Afixed_dateblock as defined below. This cannot be specified if arecurrenceblock is specified. -
recurrence- (Optional) Arecurrenceblock as defined below. This cannot be specified if afixed_dateblock is specified.
A capacity block supports the following:
-
default- (Required) The number of instances that are available for scaling if metrics are not available for evaluation. The default is only used if the current instance count is lower than the default. Valid values are between0and1000. -
maximum- (Required) The maximum number of instances for this resource. Valid values are between0and1000.
NOTE: The maximum number of instances is also limited by the amount of Cores available in the subscription.
-
minimum- (Required) The minimum number of instances for this resource. Valid values are between0and1000.
A rule block supports the following:
-
metric_trigger- (Required) Ametric_triggerblock as defined below. -
scale_action- (Required) Ascale_actionblock as defined below.
A metric_trigger block supports the following:
-
metric_name- (Required) The name of the metric that defines what the rule monitors, such asPercentage CPUforVirtual Machine Scale SetsandCpuPercentageforApp Service Plan.
NOTE: The allowed value of metric_name highly depends on the targeting resource type, please visit Supported metrics with Azure Monitor for more details.
-
metric_resource_id- (Required) The ID of the Resource which the Rule monitors. -
operator- (Required) Specifies the operator used to compare the metric data and threshold. Possible values are:Equals,NotEquals,GreaterThan,GreaterThanOrEqual,LessThan,LessThanOrEqual. -
statistic- (Required) Specifies how the metrics from multiple instances are combined. Possible values areAverage,MinandMax. -
time_aggregation- (Required) Specifies how the data that's collected should be combined over time. Possible values includeAverage,Count,Maximum,Minimum,LastandTotal. Defaults toAverage. -
time_grain- (Required) Specifies the granularity of metrics that the rule monitors, which must be one of the pre-defined values returned from the metric definitions for the metric. This value must be between 1 minute and 12 hours an be formatted as an ISO 8601 string. -
time_window- (Required) Specifies the time range for which data is collected, which must be greater than the delay in metric collection (which varies from resource to resource). This value must be between 5 minutes and 12 hours and be formatted as an ISO 8601 string. -
threshold- (Required) Specifies the threshold of the metric that triggers the scale action.
A scale_action block supports the following:
-
cooldown- (Required) The amount of time to wait since the last scaling action before this action occurs. Must be between 1 minute and 1 week and formatted as a ISO 8601 string. -
direction- (Required) The scale direction. Possible values areIncreaseandDecrease. -
type- (Required) The type of action that should occur. Possible values areChangeCount,ExactCountandPercentChangeCount. -
value- (Required) The number of instances involved in the scaling action. Defaults to1.
A fixed_date block supports the following:
-
end- (Required) Specifies the end date for the profile, formatted as an RFC3339 date string. -
start- (Required) Specifies the start date for the profile, formatted as an RFC3339 date string. -
timezone(Optional) The Time Zone of thestartandendtimes. A list of possible values can be found here. Defaults toUTC.
A recurrence block supports the following:
-
timezone- (Required) The Time Zone used for thehoursfield. A list of possible values can be found here. Defaults toUTC. -
days- (Required) A list of days that this profile takes effect on. Possible values includeMonday,Tuesday,Wednesday,Thursday,Friday,SaturdayandSunday. -
hours- (Required) A list containing a single item, which specifies the Hour interval at which this recurrence should be triggered (in 24-hour time). Possible values are from0to23. -
minutes- (Required) A list containing a single item which specifies the Minute interval at which this recurrence should be triggered.
A notification block supports the following:
-
email- (Required) Aemailblock as defined below. -
webhook- (Optional) One or morewebhookblocks as defined below.
A email block supports the following:
-
send_to_subscription_administrator- (Optional) Should email notifications be sent to the subscription administrator? Defaults tofalse. -
send_to_subscription_co_administrator- (Optional) Should email notifications be sent to the subscription co-administrator? Defaults tofalse. -
custom_emails- (Optional) Specifies a list of custom email addresses to which the email notifications will be sent.
A webhook block supports the following:
-
service_uri- (Required) The HTTPS URI which should receive scale notifications. -
properties- (Optional) A map of settings.
» Attributes Reference
The following attributes are exported:
-
id- The ID of the AutoScale Setting.
» Import
AutoScale Setting can be imported using the resource id, e.g.
terraform import azurerm_monitor_autoscale_setting.test /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/microsoft.insights/autoscalesettings/setting1