I am trying to create a custom image in my Azure DevTestLab, from a vhd image stored in the default storage account.
I started modifying the file at the GitHub repo for ARM templates for creating a custom image from a vhd.
I have already created the DevTest lab, and I can run the following Powershell command to get its data:
PS C:\git> $rid = Get-AzureRmResource -ResourceGroupName jgTl9-rg -ResourceType Microsoft.DevTestLab/labs -ResourceName jgTl9 -ApiVersion 2016-05-15
This yields a bunch of information. If I want to extract the default storage account name, I do the following:
PS C:\git> $rid.properties.defaultStorageAccount
So I know it's possible to get it. Now I have modified the variables section of the Azure build template (a JSON file) to look as follows:
"variables": {
"resourceName": "[concat(variables('existingLabName'), '/', variables('imageName'))]",
"resourceType": "Microsoft.DevTestLab/labs/customimages",
"existingLabName": "[replace(resourceGroup().name,'-rg','')]",
"storageAccountID": "/subscriptions/xxxxxxxxxxxx/resourceGroups/jgTl9-rg/providers/Microsoft.Storage/storageAccounts/djgtl91795",
"saidFrags": "[skip(split(variables('storageAccountID'), '/' ), add(length(split(variables('storageAccountID'), '/' )),-1) ) ]",
"storageAccountSuffix": "[take(variables('saidFrags'),1)[0]]",
"existingVhdUri": "[concat('https://',variables('storageAccountSuffix'),'.blob.core.windows.net/uploads/',parameters('imageFileName'))]",
"imageName": "JaysImage"
},
This code actually works when I call the New-AzureRmResourceGroupDeployment command with the azuredeploy.json and azuredeploy.parameters.json.
However, instead of hardcoding the storageAccountID variable, I'd like to extract the defaultStorageAccount from the environment. I tried something like this:
"storageAccountID": "[string( resourceId(resourceGroup().name,'MicrosoftDevTestLab/labs','jgTl9').properties.defaultStorageAccount ))",
I tried a few variations on this but nothing worked. What is the syntax I need to use to extract the same information as I have hardcoded for the storageAccountID?
(I could not find anything in Microsoft's description of template functions).