azure-sdk-for-net
azure-sdk-for-net copied to clipboard
[QUERY] Update the SKU of an App Service Plan
Library name and version
Azure.ResourceManager.AppService 1.0.0-beta.2
Query/Question
How can you update the SKU of an App Service Plan? I don't see any property in the AppServicePlanPatch object to pass it? I've tried setting the WorkerTierName to "EP2" but that results in an error:
{"Code":"BadRequest","Message":"The parameter SKU cannot be null.","Target":null,"Details":[{"Message":"The parameter SKU cannot be null."},{"Code":"BadRequest"},{"ErrorEntity":{"MessageTemplate":"The parameter {0} cannot be null.","Parameters":["SKU"],"Code":"BadRequest","Message":"The parameter SKU cannot be null."}}],"Innererror":null}
Full code sample:
var armClient = new ArmClient(new AzureCliCredential());
SubscriptionResource subscription = await armClient.GetSubscriptions().GetAsync("****");
ResourceGroupResource resourceGroup = await subscription.GetResourceGroupAsync("****");
AppServicePlanResource appServicePlan = await resourceGroup.GetAppServicePlanAsync("****");
var patch = new AppServicePlanPatch {WorkerTierName = "EP2"};
var result = await appServicePlan.UpdateAsync(patch);
Environment
Running on Windows 10 with dotnet 6.0.301
Thank you for your feedback. Tagging and routing to the team member best able to assist.
Same question; I was hoping to use this SDK to scale app service plans programatically by patching the SKU.Capacity properties. Is that possible?
@jsquire @ArcturusZhang Any update on this issue?
Any news here after the 1.0.0 release? Are there any samples on how to use AppServicePlanPatch? I get the same SKU error even just setting MaximumElasticWorkerCount on AppServicePlanPatch.
This worked for me, adding the new target plan in a separate object in the body (here B3)
{ "kind": "app", "properties": { }, "sku": { "name": "B3", "tier": "Basic", "size": "B3", "family": "B", "capacity": 1 } }
This worked for me:
see issue: #32517
string subscriptionId = "YOUR-SUBSCRIPTION-ID";
string resourceGroupName = "THE-NAME-OF-THE-RESOURCE-GROUP-THE-APP-SERVICE-PLAN-IS-IN";
string appServicePlanResourceName = "YOUR-APP-SERVICE-RESOURCE-NAME";
// client
ArmClient client = new ArmClient(new DefaultAzureCredential());
// get resource group object
SubscriptionCollection subscriptions = client.GetSubscriptions();
SubscriptionResource sub = subscriptions.Get(subscriptionId);
ResourceGroupResource resourceGroup = sub.GetResourceGroup(resourceGroupName);
// create updated service plan object
AppServicePlanData newAppServicePlanData = new AppServicePlanData(AzureLocation.WestEurope);
newAppServicePlanData.Kind = "app";
newAppServicePlanData.Sku = new AppServiceSkuDescription();
newAppServicePlanData.Sku.Name = "P1v2";
newAppServicePlanData.Sku.Tier = "PremiumV2";
newAppServicePlanData.Sku.Size = "P1v2";
newAppServicePlanData.Sku.Family = "P";
newAppServicePlanData.Sku.Capacity = 1;
// get service plan
AppServicePlanCollection collection = resourceGroup.GetAppServicePlans();
// update service plan
var result = collection.CreateOrUpdate(
waitUntil: Azure.WaitUntil.Completed,
name: appServicePlanResourceName,
data: newAppServicePlanData
);
Ran into the same problem trying to programmatically scale out
The above code worked, I refactored it a little it to just scale the instances:
var credential = new DefaultAzureCredential();
ArmClient client = new ArmClient(credential);
// get resource group object
SubscriptionCollection subscriptions = client.GetSubscriptions();
SubscriptionResource sub = subscriptions.Get(configuration.SubscriptionId.ToString());
ResourceGroupResource resourceGroup = sub.GetResourceGroup(configuration.ResourceGroupName);
var resourceIdentifier = $"/subscriptions/{configuration.SubscriptionId}/resourcegroups/{configuration.ResourceGroupName}/providers/Microsoft.Web/serverFarms/{configuration.AppServicePlanName}";
var appServicePlan = client.GetAppServicePlanResource(new ResourceIdentifier(resourceIdentifier));
appServicePlan = (await appServicePlan.GetAsync()).Value;
appServicePlan.Data.Sku.Capacity += scaleOutWithXInstances;
// get service plan
AppServicePlanCollection collection = resourceGroup.GetAppServicePlans();
// update service plan
var result = collection.CreateOrUpdate(
waitUntil: Azure.WaitUntil.Completed,
name: configuration.AppServicePlanName,
data: appServicePlan.Data
);
Hi @Zenuka, we deeply appreciate your input into this project. Regrettably, this issue has remained unresolved for over 2 years and inactive for 30 days, leading us to the decision to close it. We've implemented this policy to maintain the relevance of our issue queue and facilitate easier navigation for new contributors. If you still believe this topic requires attention, please feel free to create a new issue, referencing this one. Thank you for your understanding and ongoing support.