{"id":3450,"date":"2020-07-23T12:13:37","date_gmt":"2020-07-23T11:13:37","guid":{"rendered":"https:\/\/www.lieben.nu\/liebensraum\/?p=3450"},"modified":"2020-07-23T12:13:37","modified_gmt":"2020-07-23T11:13:37","slug":"azure-static-website-with-cdn-getting-the-regional-code-for-an-arm-template","status":"publish","type":"post","link":"https:\/\/lieben.nu\/liebensraum\/2020\/07\/azure-static-website-with-cdn-getting-the-regional-code-for-an-arm-template\/","title":{"rendered":"Azure static website with CDN, getting the regional code for an ARM template"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">When deploying a <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/storage\/blobs\/storage-blob-static-website\" target=\"_blank\">Static Website to Azure storage<\/a> with CDN, the CDN endpoint requires the static website hostname. MS docs don&#8217;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 <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/azure-resource-manager\/templates\/template-functions-resource#reference\" target=\"_blank\">Reference function in ARM<\/a>, which returned the full static website endpoint url including the zone identifier:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; auto-links: false; title: ; notranslate\" title=\"\">\n\"&#x5B;reference(concat('Microsoft.Storage\/storageAccounts\/', variables('storageAccountName')), '2019-06-01', 'Full').properties.primaryEndpoints.web]\"\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Sadly, &#8216;Reference&#8217; is not available for use in other functions, such as Concat, so you&#8217;ll have to pass this as output from the storage template to your CDN template instead of combining both into a single template.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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 <a rel=\"noreferrer noopener\" href=\"https:\/\/stackoverflow.com\/questions\/51149262\/enable-azure-storagev2-static-website-preview-feature-using-arm-template\" target=\"_blank\">still requires using PS or Az Cli<\/a>. But we&#8217;re in luck, running PowerShell in DevOps <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/devops\/pipelines\/scripts\/powershell?view=azure-devops&amp;tabs=yaml\" target=\"_blank\">is easy<\/a> \ud83d\ude42<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s two ARM templates to showcase the Storage Account + CDN:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a rel=\"noreferrer noopener\" href=\"https:\/\/gitlab.com\/Lieben\/assortedFunctions\/-\/blob\/master\/ARM%20templates\/cdnForStaticWebsite.json\" target=\"_blank\">CDN Template<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/gitlab.com\/Lieben\/assortedFunctions\/-\/blob\/master\/ARM%20templates\/cdnForStaticWebsite.json\" target=\"_blank\" rel=\"noreferrer noopener\">Storage Account<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then this is what the Pipeline more or less looks like:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1572\" height=\"400\" src=\"https:\/\/www.lieben.nu\/liebensraum\/wp-content\/uploads\/2020\/07\/image.png\" alt=\"\" class=\"wp-image-3453\" srcset=\"https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2020\/07\/image.png 1572w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2020\/07\/image-300x76.png 300w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2020\/07\/image-1024x261.png 1024w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2020\/07\/image-768x195.png 768w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2020\/07\/image-1536x391.png 1536w\" sizes=\"auto, (max-width: 1572px) 100vw, 1572px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">the processStorageAccountOutput.ps1 contains:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\nParam(\n  &#x5B;parameter(Mandatory=$true)]\n  $storageAccountOutput\n)\n\nWrite-Host \"##vso&#x5B;task.setvariable variable=storageAccountWebEndpointURI;]$($(ConvertFrom-Json $storageAccountOutput).WebEndpointURI.value)\"\nWrite-Host \"##vso&#x5B;task.setvariable variable=storageAccountName;]$($(ConvertFrom-Json $storageAccountOutput).storageAccountName.value.Replace('https:\/\/','').Split('.')&#x5B;0])\"\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">And the Azure Cli step in the DevOps pipeline is configured like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"890\" height=\"321\" src=\"https:\/\/www.lieben.nu\/liebensraum\/wp-content\/uploads\/2020\/07\/image-1.png\" alt=\"enabling azure static website through azure cli in azure devops pipeline\" class=\"wp-image-3454\" srcset=\"https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2020\/07\/image-1.png 890w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2020\/07\/image-1-300x108.png 300w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2020\/07\/image-1-768x277.png 768w\" sizes=\"auto, (max-width: 890px) 100vw, 890px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>When deploying a Static Website to Azure storage with CDN, the CDN endpoint requires the static website hostname. MS docs don&#8217;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 &hellip; <a href=\"https:\/\/lieben.nu\/liebensraum\/2020\/07\/azure-static-website-with-cdn-getting-the-regional-code-for-an-arm-template\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Azure static website with CDN, getting the regional code for an ARM template<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[49,5],"tags":[],"class_list":["post-3450","post","type-post","status-publish","format-standard","hentry","category-arm","category-azure"],"_links":{"self":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/3450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/comments?post=3450"}],"version-history":[{"count":0,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/3450\/revisions"}],"wp:attachment":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/media?parent=3450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/categories?post=3450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/tags?post=3450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}