Moving Application Insights resources between subscriptions in Azure

category: [ Azure ] tags: [ Application Insights ] [ Azure ] [ PowerShell ]
created: 03 Jan 2018 @ 11:10 modified: 03 Jan 2018 @ 11:23


There is documentation available for Move resources to new resource group or subscription but things are easier to do with exact sample code so here it goes Smile. The steps below will work for moving between Resource Groups as well, you'll just skip some steps that would be obvious.

Limitations

There are a couple limitations which make sense like resources needing to be in the same directory and not every services is supported to move which is all detailed on the link mentioned above where all the limitations are documented.

Step by Step

First off we need to login

Then let's list all our subscriptions that we have access to

You should see a result similar to the below

image 

Now we need to set the source and destination subscription id from the list above and then check if the resource type is registered in the destination subscription

Once done we can check the resource providers to make sure the insights resource provider is enabled, usually this would not be enabled if you haven't created the resource in the destination subscription before. We'll first change the context to the subscription to our destination subscription id and then list the resource providers

If like with me it's not registered

image

you can use the script below to enable the provider

you should see a message like below saying it's Registering

image

This takes a little while to run sometimes, you can run the last part of the script above every now and then to see when it's registered

You should see it saying Registered as below when done

image

Before doing the switch we need to make sure we have a resource group in the target subscription to move the resource to, you can create a new resource group like below

We can now get our source resource Id and perform the move. For this we are going to switch context to the source subscription, find the resource we want, get it's resource id and then finally call Move-AzureRmResource to move the resource

This would take a little while to complete usually, when done your resource should be in the subscription you want it in...if you there's a good chance you going to be creating a support ticket soon Smile with tongue out. This is where you would leave off the subscription id if you are moving between resource groups instead of subscriptions

last steps

All that's left now is to go through any dashboards and existing scripts that reference this resource and update them. Because the resource is no longer at it's old location your dashboards will become less 'metricky' Smile 

image

Full script

The full script for the above is below including some variables to make the replacements easier

Conclusion

There is quite a lot of functionality that is available to us using the sdks like PowerShell that we can't do in the Azure Portal UI. Sometimes you just need to figure it out, in this case there was a good doc to follow.

Happy Migrating Open-mouthed smile

ABOUT ME

Gordon Beeming works at Nologo Studios in the sunny city of Durban, South Africa. He is the Lead for the Data and Services Team and has a strong focus on Developer Efficiencies and R&D. When he's not hacking away at a keyboard in Visual Studio he'll generally be relaxing with his family or hitting the black top getting in some mileage. He is a Visual Studio ALM Ranger and Visual Studio ALM MVP.

Follow me on Strava

TOOLS

I plan on writing a bunch of online tools and sharing the code for how I made those tools. If you have any feedback you can ping me on Twitter (@GordonBeeming) or mail me [email protected].