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_service_plan] Support for the new Automatic Scaling (currently in preview) #22313

Open
1 task done
peruzzof opened this issue Jun 28, 2023 · 4 comments · May be fixed by #28524
Open
1 task done

[azurerm_service_plan] Support for the new Automatic Scaling (currently in preview) #22313

peruzzof opened this issue Jun 28, 2023 · 4 comments · May be fixed by #28524

Comments

@peruzzof
Copy link

peruzzof commented Jun 28, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

There is a feature in preview for P2v2 and Pv3 instances since 8/May/23 to use the automatic scaling, that is similar to what exist for the Elastic instances (to be used for Functions), but it seems that currently there is no support for it.

Even considering that this is a preview feature it will be better to use the current provider instead of the AzPI

New or Affected Resource(s)/Data Source(s)

azurerm_service_plan

Potential Terraform Configuration

resource "azurerm_service_plan" "example" {
  name                = "example"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  os_type             = "Linux"
  sku_name            = "P2v2"
  elastic_scale_enabled = true
  maximum_elastic_worker_count  = 10
}

References

https://azure.microsoft.com/en-us/updates/preview-automatic-scaling-for-app-service-web-apps/
https://learn.microsoft.com/en-us/azure/app-service/manage-automatic-scaling?tabs=azure-portal
https://learn.microsoft.com/en-us/azure/templates/microsoft.web/2022-03-01/serverfarms?pivots=deployment-language-bicep

@eltimmo
Copy link
Contributor

eltimmo commented Apr 9, 2024

This is GA now, in the interim it can be enabled using azapi

resource "azapi_update_resource" "elastic_scale" {

  type      = "Microsoft.Web/serverfarms@2022-09-01"
  name      = {service plan name}
  parent_id = {resource group id}
  body = jsonencode({
    properties = {
      elasticScaleEnabled = true
    }
  })

}

@sjesse
Copy link

sjesse commented May 23, 2024

I have also solved this using azapi this includes the per app settings:

resource "azapi_update_resource" "elastic_web_app_scale" {
  type      = "Microsoft.Web/sites@2022-09-01"
  name      = azurerm_windows_web_app.resource.name
  parent_id = azurerm_resource_group.resource.id
  body = jsonencode({
    properties = {
      siteConfig = {
        minimumElasticInstanceCount = 1  # Always ready instances
        elasticWebAppScaleLimit     = 10 # Maximum scale limit
      }
    }
  })
}

resource "azapi_update_resource" "elastic_service_plan_scale" {
  type      = "Microsoft.Web/serverfarms@2022-09-01"
  name      = azurerm_service_plan.resource.name
  parent_id = azurerm_resource_group.resource.id
  body = jsonencode({
    properties = {
      elasticScaleEnabled       = true
      maximumElasticWorkerCount = 12 # Maximum burst
    }
  })

}

@Vdraksic
Copy link

Vdraksic commented Aug 1, 2024

I have also solved this using azapi this includes the per app settings:

resource "azapi_update_resource" "elastic_web_app_scale" {
  type      = "Microsoft.Web/sites@2022-09-01"
  name      = azurerm_windows_web_app.resource.name
  parent_id = azurerm_resource_group.resource.id
  body = jsonencode({
    properties = {
      siteConfig = {
        minimumElasticInstanceCount = 1  # Always ready instances
        elasticWebAppScaleLimit     = 10 # Maximum scale limit
      }
    }
  })
}

resource "azapi_update_resource" "elastic_service_plan_scale" {
  type      = "Microsoft.Web/serverfarms@2022-09-01"
  name      = azurerm_service_plan.resource.name
  parent_id = azurerm_resource_group.resource.id
  body = jsonencode({
    properties = {
      elasticScaleEnabled       = true
      maximumElasticWorkerCount = 12 # Maximum burst
    }
  })

}

This works perfectly, thank you.
I did get an intermediate error since i had zonal balancing enabled. I solved it by switching to manual, settings instance count to 3 and then switching back to automatic.
You can then set/update all the variables with this snipet.

This currently does not work for functions and function service plans, im guessing the siteConfig properties are a bit different, I will try to research it and set it up. Will update

@xiaxyi
Copy link
Contributor

xiaxyi commented Jan 14, 2025

Thanks all, working on it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants