{"id":606,"date":"2021-10-22T19:19:19","date_gmt":"2021-10-22T19:19:19","guid":{"rendered":"https:\/\/thecloudmarathoner.com\/?p=606"},"modified":"2021-10-25T02:39:08","modified_gmt":"2021-10-25T02:39:08","slug":"hardening-parameter-inputs-on-azure-bicep-files","status":"publish","type":"post","link":"https:\/\/elyusubov.com\/index.php\/2021\/10\/22\/hardening-parameter-inputs-on-azure-bicep-files\/","title":{"rendered":"Hardening parameter inputs on Azure Bicep files"},"content":{"rendered":"\n<p>Hello Cloud Marathoners,<\/p>\n\n\n\n<p>In my previous Azure Bicep post, I wrote about<a href=\"https:\/\/thecloudmarathoner.com\/index.php\/2021\/10\/15\/four-parameterization-options-for-your-azure-bicep-deployments\/\" target=\"_blank\" rel=\"noreferrer noopener\"> four parameterization options<\/a> that could be used with Bicep language. We also looked into the Azure Bicep resource templates, and how they help to author and manage Azure resources&nbsp;more cleanly and easily.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"574\" src=\"\/wp-content\/uploads\/2021\/10\/Azure-Bicep-Tips-2-1024x574.jpg\" alt=\"\" class=\"wp-image-624\" srcset=\"\/wp-content\/uploads\/2021\/10\/Azure-Bicep-Tips-2-1024x574.jpg 1024w, \/wp-content\/uploads\/2021\/10\/Azure-Bicep-Tips-2-300x168.jpg 300w, \/wp-content\/uploads\/2021\/10\/Azure-Bicep-Tips-2-768x430.jpg 768w, \/wp-content\/uploads\/2021\/10\/Azure-Bicep-Tips-2.jpg 1092w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption>Azure Bicep Tips &#8211; Hardening parameter inputs<\/figcaption><\/figure><\/div>\n\n\n\n<p>Now, I would like to share a couple tips on how to harden your parameter inputs. This will help you to avoid deployment errors that you could easily prevent by restricting and checking Bicep parameter values.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Tip # 1: Min and Max length of resource names<\/h3>\n\n\n\n<p>In our previous post, we have built and demoed the <strong>webapp-service-w-param.bicep<\/strong> file. It had no parameter input validation. Thus, that template is open for failures when you enter <code>'a' <\/code>for the <code>appServiceAppName<\/code> input parameter. Here is the <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/ElYusubov\/Learn-Bicep\/tree\/main\/param-files\" target=\"_blank\">link to the repo<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"686\" height=\"549\" src=\"\/wp-content\/uploads\/2021\/10\/image-4.png\" alt=\"\" class=\"wp-image-616\" srcset=\"\/wp-content\/uploads\/2021\/10\/image-4.png 686w, \/wp-content\/uploads\/2021\/10\/image-4-300x240.png 300w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><figcaption>webapp-service-w-param.bicep<\/figcaption><\/figure>\n\n\n\n<p>However, it is pretty straightforward to avoid such false entries by checking the allowed name length of the<code> Microsoft.Web\/serverFarms <\/code>resource in the Microsoft docs <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/azure-resource-manager\/management\/resource-name-rules#microsoftweb\" target=\"_blank\">Resource name rules<\/a> page.<\/p>\n\n\n\n<p>Based on &#8220;Resource name rules&#8221; page we can add following functions:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"462\" height=\"95\" src=\"\/wp-content\/uploads\/2021\/10\/image-5.png\" alt=\"\" class=\"wp-image-617\" srcset=\"\/wp-content\/uploads\/2021\/10\/image-5.png 462w, \/wp-content\/uploads\/2021\/10\/image-5-300x62.png 300w\" sizes=\"auto, (max-width: 462px) 85vw, 462px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The <code>@minLength<\/code> and <code>@maxLength<\/code> function are going to define and enforce min and max length of the parameter, while <code>@description<\/code> will help to define the purpose of the parameter. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Tip # 2: Defining purpose of the parameter<\/h3>\n\n\n\n<p>It is always helpful to add meaningful description to your parameters, even though it is not required by Azure Bicep template. Believe it or not, people who are new to your code will appreciate it.  For example: we have a location parameter in our template, and adding the following description clarifies the purpose of this parameter for everyone, including myself, later in a month when I am re-visiting my code.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"703\" height=\"295\" src=\"\/wp-content\/uploads\/2021\/10\/image-6.png\" alt=\"\" class=\"wp-image-618\" srcset=\"\/wp-content\/uploads\/2021\/10\/image-6.png 703w, \/wp-content\/uploads\/2021\/10\/image-6-300x126.png 300w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Tip # 3: Restricting parameter value entries that match your organization&#8217;s policy<\/h3>\n\n\n\n<p>The final tip is already revealed in our screen-shot above. It makes a valid and important sense to enforce your organization&#8217;s Azure policies on any provisioning scripts, in addition to the Azure Policies.<\/p>\n\n\n\n<p>In our example: we are restricting deployment of Azure resources only into the following Azure regions to comply with the company policy to make every party happy.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"373\" height=\"213\" src=\"\/wp-content\/uploads\/2021\/10\/image-7.png\" alt=\"\" class=\"wp-image-619\" srcset=\"\/wp-content\/uploads\/2021\/10\/image-7.png 373w, \/wp-content\/uploads\/2021\/10\/image-7-300x171.png 300w\" sizes=\"auto, (max-width: 373px) 85vw, 373px\" \/><\/figure>\n\n\n\n<p> <\/p>\n\n\n\n<p>Thus, I have shared a few tips that you could use to harden your Azure Bicep code and avoid some common deployment errors in advance.<\/p>\n\n\n\n<p>Here is the complete view into our hardened webapp-service Bicep file:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"780\" height=\"850\" src=\"\/wp-content\/uploads\/2021\/10\/image-8.png\" alt=\"\" class=\"wp-image-620\" srcset=\"\/wp-content\/uploads\/2021\/10\/image-8.png 780w, \/wp-content\/uploads\/2021\/10\/image-8-275x300.png 275w, \/wp-content\/uploads\/2021\/10\/image-8-768x837.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Summary<\/h3>\n\n\n\n<p>Preventing deployment failures, especially the once that are caused by invalid input parameters are an easy fix on an Azure Bicep language. Checking the resource name restrictions and allowed values is one easy tip to prevent those errors. I would recommend checking the Microsoft documentation on &#8220;<a rel=\"noreferrer noopener\" href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/azure-resource-manager\/management\/resource-name-rules\" target=\"_blank\">Naming rules and restrictions for Azure resources<\/a>&#8221; and bookmark it for your reference.<\/p>\n\n\n\n<p>Thank you \ud83d\ude4f for reading this post and learning how to prevent Azure Bicep deployment failures by hardening the input parameter values. <\/p>\n\n\n\n<p>Please check out the <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/ElYusubov\/Learn-Bicep\" target=\"_blank\">Learn Bicep<\/a> GitHub repo, and follow it. <br>Thanks, \ud83d\ude4f \ud83d\ude4c!<\/p>\n\n\n\n<p>Stay tuned for more Azure automation &amp; Azure Bicep posts.<\/p>\n\n\n\n<p>F\u1d0f\u029f\u029f\u1d0f\u1d21 \u1d0d\u1d07 \ud83c\udfaf \u1d00\u0274\u1d05 become \u1d00&nbsp;<a href=\"https:\/\/www.linkedin.com\/feed\/hashtag\/?keywords=cloudmarathoner&amp;highlightedUpdateUrns=urn%3Ali%3Aactivity%3A6831288713784410112\">#cloudmarathoner<\/a>&nbsp;\u26c5\ud83c\udfc3\u200d\u2642\ufe0f\ud83c\udfc3\u200d\u2640\ufe0f &#8211; \ud835\udc0b\ud835\udc04\ud835\udc13&#8217;\ud835\udc12 \ud835\udc02\ud835\udc0e\ud835\udc0d\ud835\udc0d\ud835\udc04\ud835\udc02\ud835\udc13 \ud83d\udc4d<\/p>\n<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_606\" class=\"pvc_stats all  \" data-element-id=\"606\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p><div class=\"pvc_clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Hello Cloud Marathoners, In my previous Azure Bicep post, I wrote about four parameterization options that could be used with Bicep language. We also looked into the Azure Bicep resource templates, and how they help to author and manage Azure resources&nbsp;more cleanly and easily. Now, I would like to share a couple tips on how &hellip; <a href=\"https:\/\/elyusubov.com\/index.php\/2021\/10\/22\/hardening-parameter-inputs-on-azure-bicep-files\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Hardening parameter inputs on Azure Bicep files&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,2,18],"tags":[],"class_list":["post-606","post","type-post","status-publish","format-standard","hentry","category-azure-bicep","category-infrastructure-as-code-iac","category-azure"],"_links":{"self":[{"href":"https:\/\/elyusubov.com\/index.php\/wp-json\/wp\/v2\/posts\/606","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elyusubov.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elyusubov.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elyusubov.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elyusubov.com\/index.php\/wp-json\/wp\/v2\/comments?post=606"}],"version-history":[{"count":11,"href":"https:\/\/elyusubov.com\/index.php\/wp-json\/wp\/v2\/posts\/606\/revisions"}],"predecessor-version":[{"id":635,"href":"https:\/\/elyusubov.com\/index.php\/wp-json\/wp\/v2\/posts\/606\/revisions\/635"}],"wp:attachment":[{"href":"https:\/\/elyusubov.com\/index.php\/wp-json\/wp\/v2\/media?parent=606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elyusubov.com\/index.php\/wp-json\/wp\/v2\/categories?post=606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elyusubov.com\/index.php\/wp-json\/wp\/v2\/tags?post=606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}