azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

[QUERY] Update the SKU of an App Service Plan

Open Zenuka opened this issue 2 years ago • 8 comments

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

Zenuka avatar Jun 27 '22 11:06 Zenuka

Thank you for your feedback. Tagging and routing to the team member best able to assist.

jsquire avatar Jun 27 '22 12:06 jsquire

Same question; I was hoping to use this SDK to scale app service plans programatically by patching the SKU.Capacity properties. Is that possible?

ransagy avatar Aug 17 '22 13:08 ransagy

@jsquire @ArcturusZhang Any update on this issue?

niels-vdz avatar Oct 11 '22 11:10 niels-vdz

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.

aduggleby avatar Nov 14 '22 19:11 aduggleby

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 } }

raulgt avatar Nov 23 '22 19:11 raulgt

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
);

iliosana avatar Dec 12 '22 12:12 iliosana

Ran into the same problem trying to programmatically scale out

eriksteinebach avatar Dec 30 '22 23:12 eriksteinebach

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
                );

eriksteinebach avatar Dec 31 '22 00:12 eriksteinebach

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.

github-actions[bot] avatar Jun 28 '24 18:06 github-actions[bot]