Programmatically Change Azure Log Analytics Pricing Model


Microsoft recently introduced a new model for purchasing Azure Log Analytics. To use this new model you will basically have to enable it on per subscription bases. In short you can either continue to use the old models or flip a switch on your subscription to use the new model. You cannot use both models for different workspaces in your subscription and you cannot move between the old models and the new ones without flipping that switch. Of course flipping that switch is easy as going into the Azure Portal -> Azure Monitor -> Usage and estimated costs blade but what about if you want to do this programmatically? Apparently there is a way to do it that way and in this blog post I will show you how.

In order to be able to do this programmatically we will use PowerShell and the AzureRM PS modules. The first thing to do is to get what is the current state of your Azure subscription. We can get it by executing Azure resource action listmigrationdate on the Microsoft.Inisghts (Azure Monitor) resource provider.

Invoke-AzureRmResourceAction `
        -ResourceId "/subscriptions/3c1d68b5-4064-4622-92e4-e0378145922c/providers/microsoft.insights" `
        -ApiVersion "2017-10-01" `
        -Action listmigrationdate `
        -Force 

By executing the command above you will get similar output. Remember to change the subscription ID to yours.

isGrandFatherableSubscription optedInDate
----------------------------- -----------
                         True

The output shows two things:

  • If your subscription is allowed to use the old models. If the value for isGrandFatherableSubscription is False that basically means that you can only use the new pricing model. This is because your subscription was created after the announced changes. If the value is True your subscription was created before the announcement of the new model which means you can opt-in if you want.
  • If you have opted-in for using the new model. If the value of optedInDate is populated with a date you basically have enabled the new model on your subscription. If there is no value for optedInDate you are still using the old models.

Now that we know how to get the state how we can actually switch to the new model with code? This is easy as executing the command below:

Invoke-AzureRmResourceAction `
        -ResourceId "/subscriptions/3c1d68b5-4064-4622-92e4-e0378145922c/providers/microsoft.insights" `
        -ApiVersion "2017-10-01" `
        -Action migratetonewpricingmodel `
        -Force

As you can see we are again invoking an action but this time is migratetonewpricingmodel. After executing that action optedInDate value will be populated with the date when the migration was done. In case you want to go back to the old models there is action for that as well:

Invoke-AzureRmResourceAction `
        -ResourceId "/subscriptions/3c1d68b5-4064-4622-92e4-e0378145922c/providers/microsoft.insights" `
        -ApiVersion "2017-10-01" `
        -Action rollbacktolegacypricingmodel `
        -Force

Remember that you can only execute the above two actions if the value for isGrandFatherableSubscription is True.

Note: Customers who purchased Microsoft Operations Management Suite E1 and E2 are eligible for per-node data ingestion entitlements for Log Analytics and Application Insights. To receive these entitlements for Log Analytics workspaces or Application Insights resources in a given subscription, that subscription’s pricing model must remain in the pre-April 2018 pricing model where the Log Analytics “Per-node (OMS)” pricing tier and the Application Insights “Enterprise” pricing plan are available. Depending on the number of nodes of the suite that your organization purchased, moving some subscriptions to the new pricing model may still be advantageous, but this requires careful consideration. Source here.

I hope this was helpful.

One thought on “Programmatically Change Azure Log Analytics Pricing Model

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.