When deploying a Static Website to Azure storage with CDN, the CDN endpoint requires the static website hostname. MS docs don’t show how to retrieve this data (other than clicking in the portal). Playing around with Fiddler, I noticed a call to management.azure.com when enabling a static site manually and tried to reproduce this with the Reference function in ARM, which returned the full static website endpoint url including the zone identifier:
"[reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName')), '2019-06-01', 'Full').properties.primaryEndpoints.web]"
Sadly, ‘Reference’ is not available for use in other functions, such as Concat, so you’ll have to pass this as output from the storage template to your CDN template instead of combining both into a single template.
This brings us one step closer to a full ARM deployment of a static website, only actually enabling the static website feature on the storage account still requires using PS or Az Cli. But we’re in luck, running PowerShell in DevOps is easy 🙂
Here’s two ARM templates to showcase the Storage Account + CDN:
Then this is what the Pipeline more or less looks like:
the processStorageAccountOutput.ps1 contains:
Param( [parameter(Mandatory=$true)] $storageAccountOutput ) Write-Host "##vso[task.setvariable variable=storageAccountWebEndpointURI;]$($(ConvertFrom-Json $storageAccountOutput).WebEndpointURI.value)" Write-Host "##vso[task.setvariable variable=storageAccountName;]$($(ConvertFrom-Json $storageAccountOutput).storageAccountName.value.Replace('https://','').Split('.'))"
And the Azure Cli step in the DevOps pipeline is configured like this: