Some of you will already know about new cloud locations that Azure is creating. Because of this, new uri’s are there, so a new way of getting them is being used now.
Working on Azure Templates or PowerShell, when we need to reference, in example, a blob of a storage account, we usually type this: “http://’StorageAccountName’".

If we were using a German datacentre we would need to turn “” into “”. This means that a template or a script is only valid for one kind of cloud and we would need to modify both if we want to use them on another cloud.

Fortunately, there is another way to do this making our codes valid everywhere. I’m going to show you some examples of how we would get the uri both on an Azure template and a PowerShell script.

Azure Template:

Old way: 

"storageUri": [concat('http://',variables('StorageAccountName'),'')]"

New way:

"storageUri": "[concat(reference(resourceId('Microsoft.Storage/storageAccounts/', variables('StorageAccountName'))).primaryEndpoints.blob)]"

PowerShell script:

Old way:

$storageUri = “http://”  + $StorageAccountName + “”

New way:

$storageUri = (Get-AzureRmStorageAccount -Name $StorageAccountName -ResourceGroupName $ResourceGroupName).PrimaryEndpoints.Blob

We will get and uri like this one: “” This way we make our codes valid everywhere for both templates and scripts.

Furthermore, notice that “primaryEndpoints” is our key here and that we have these other functions available: PrimaryEndpoints.File, PrimaryEndpoints.Queue and PrimaryEndpoints.Table. These will retrieve the “file.core”, “queue.core” and “table.core” uri’s if we need them.

Author bio

Ivan Chesa
Ivan Chesa
Junior Developer
I’m part of the SharePoint development team. Besides working on client and internal projects, I enjoy learning more about other technologies like Azure. In my spare time I love playing video games with friends and I also like to watch TV shows.


comments powered by Disqus

Related Articles

Sign up to our ClearThought newsletter

Get inspired and learn something new by subscribing to our FREE newsletter. It’s full of ClearPeople's thought-leadership whitepapers, blogs, events, and much more. We promise to not use your email for spam.

Closing this message and/or accessing our website tells us you are happy to receive all cookies on the ClearPeople website.
However, if you would like to, you can change your cookies settings at any time.