azurerm_service_plan: error "maximum_elastic_worker_count can only be specified" after disabling premium_plan_auto_scale_enabled

Description

We are encountering an issue with the Terraform AzureRM provider when transitioning an App Service / Function App Premium plan from elastic autoscaling to fixed manual scaling.

Initially, the service plan was configured with elastic autoscaling enabled:

premium_plan_auto_scale_enabled = true
maximum_elastic_worker_count   = 4

Later, we disabled elastic autoscaling and switched to a fixed worker count managed by Terraform:

premium_plan_auto_scale_enabled = false
worker_count = 3

At the time of this change, the Terraform configuration still had:

maximum_elastic_worker_count = 4

The scaling to 3 instances was performed through Terraform, not manually via the Azure Portal.


Observed Behavior

When Terraform is run again, it fails with the following validation error:

maximum_elastic_worker_count can only be specified with Elastic Premium SKUs or with Premium SKUs that have premium_plan_auto_scale_enabled set to true

Upon inspecting the Terraform state file, we observe that the state now contains:

maximum_elastic_worker_count = 3

even though:

  • premium_plan_auto_scale_enabled is set to false

  • The Terraform configuration still specifies maximum_elastic_worker_count = 4

  • The provider schema does not allow maximum_elastic_worker_count when autoscaling is disabled

This results in persistent state drift and a plan failure before Terraform can proceed.