I am trying to access an app service plan's pricing tier and then update it from within c# code.
I have working code using the deprecated Microsoft.Azure.Magement.Fluent libraries that I am trying to upgrade to the latest Azure.ResourceManager.Resources library, without success.
My existing code (using the old deprecated libraries) is as follows
public static string UpgradeServicePlanPricingTier(string servicePlan, PricingTier currentPricingTier, PricingTier newPricingTier, int capacity)
{
var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientID, clientSecret, tenantID, AzureEnvironment.AzureGlobalCloud);
var azure = Microsoft.Azure.Management.Fluent.Azure
.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Authenticate(credentials)
.WithDefaultSubscription();
var plan = azure.AppServices.AppServicePlans.List().SingleOrDefault(p => p.Name == servicePlan);
if (plan == null)
throw new ApplicationException("Unknown Service Plan");
if (plan.PricingTier.SkuDescription.Name != currentPricingTier.SkuDescription.Name)
throw new ApplicationException("Plan currently in " + plan.PricingTier.SkuDescription.Name + " pricing tier");
plan
.Update()
.WithPricingTier(newPricingTier)
.WithCapacity(capacity)
.Apply();
return plan.PricingTier.SkuDescription.Name;
}
public static PricingTier GetServicePlanPricingTier(string servicePlan)
{
var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientID, clientSecret, tenantID, AzureEnvironment.AzureGlobalCloud);
var azure = Microsoft.Azure.Management.Fluent.Azure
.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Authenticate(credentials)
.WithDefaultSubscription();
var plan = azure.AppServices.AppServicePlans.List().SingleOrDefault(p => p.Name == servicePlan);
if (plan == null)
throw new ApplicationException("Unknown Service Plan");
return plan.PricingTier;
}
All of the examples of the new libraries seem to be for a preview version (1.0.0-preview.1) where I can access ResourcesManagementClient to find the correct plan and then check its sku (for capacity and tier name).
Its not obvious how I would update the sku for a plan though, to put it on a new pricing tier.
When I upgrade the library to any version after the preview (currently 1.3.1), I no longer have access to the ResourcesManagementClient. Is this an issue with the nuget install somehow, or has the class been moved or changed?
The code using the new library (where only the preview version seems to work) is currently
private void Test()
{
ClientSecretCredential creds = new ClientSecretCredential(tenantID, clientID, clientSecret);
var client = new ResourcesManagementClient("{my subscription}", creds);
var plan = client.Resources.List().FirstOrDefault(p => p.Name == "{my app service plan name}");
if (plan != null)
{
int? currentCapacity = plan.Sku.Capacity;
string currentName = plan.Sku.Name;
//how do I update these?
}
}
Any help with updating the pricing tier and updating to the latest library version would be much appreciated, or if someone can point me to some up to date azure docs that cover this stuff that would be fantastic too.
cheers Steve