Terraform v0.11.11
provider.azurerm v1.21.0
resource "azurerm_autoscale_setting" "autoscale_setting" {
name = "myAutoscaleSetting"
resource_group_name = "${var.resource_group_name}"
location = "${var.resource_group_location}"
target_resource_id = "${var.app_service_plan_id}"
profile {
name = "CpuProfile"
capacity {
default = 1
minimum = 1
maximum = 10
}
rule {
metric_trigger {
metric_name = "CpuPercentage"
metric_resource_id = "${var.app_service_plan_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 = "CpuPercentage"
metric_resource_id = "${var.app_service_plan_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 = false
send_to_subscription_co_administrator = false
}
}
}
module.autoscale_setting.azurerm_autoscale_setting.autoscale_setting: 1 error(s) occurred:
azurerm_autoscale_setting.autoscale_setting: Error creating AutoScale Setting "myAutoscaleSetting" (Resource Group "ticketcms-stg"): insights.AutoscaleSettingsClient#CreateOrUpdate: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>
Could someone help me please ?
Sorry forgot to mention this is for Azure app service not for Azure VM
Workaround: Delete the JSON _Autoscale setting name_ in the portal under the app plan settings > scale out. Retry terraform apply. Happens when an autoscale plan was initially created in portal
thanks @cornebester saved me from going mad! :)
when is this going to be fixed? workaround is great but the automation fails until this is fixed.
Somehow the issue survived destroying and re-creating the App Service Plan. :'( Thanks for the workaround though.
Hi all, From azurerm version 2.0, resource "azurerm_autoscale_setting" has been renamed to "azurerm_monitor_autoscale_setting". I try following script using latest azurerm provider but I could not reproduced it.
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
location = "westeurope"
name = "qwertyuiop"
}
resource "azurerm_app_service_plan" "test" {
name = "acctestASP-cz"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
kind = "windows"
reserved = false
is_xenon = true
sku {
tier = "PremiumContainer"
size = "PC2"
}
}
resource "azurerm_app_service" "test" {
name = "acctest-cz-app-service"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
app_service_plan_id = azurerm_app_service_plan.test.id
site_config {
windows_fx_version = "DOCKER|mcr.microsoft.com/azure-app-service/samples/aspnethelloworld:latest"
}
identity {
type = "SystemAssigned"
}
}
resource "azurerm_monitor_autoscale_setting" "autoscale_setting" {
name = "myAutoscaleSetting1"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
target_resource_id = azurerm_app_service_plan.test.id
profile {
name = "CpuProfile"
capacity {
default = 1
minimum = 1
maximum = 10
}
rule {
metric_trigger {
metric_name = "CpuPercentage"
metric_resource_id = azurerm_app_service_plan.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 = "CpuPercentage"
metric_resource_id = azurerm_app_service_plan.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 = false
send_to_subscription_co_administrator = false
}
}
}
Could anyone confirm it or Did I missed some step?
Most helpful comment
Workaround: Delete the JSON _Autoscale setting name_ in the portal under the app plan settings > scale out. Retry terraform apply. Happens when an autoscale plan was initially created in portal