{"id":829,"date":"2022-03-01T15:30:00","date_gmt":"2022-03-01T15:30:00","guid":{"rendered":"https:\/\/thecloudmarathoner.com\/?p=829"},"modified":"2022-03-01T14:02:41","modified_gmt":"2022-03-01T14:02:41","slug":"simplifying-azure-iac-with-azure-bicep-child-resources","status":"publish","type":"post","link":"https:\/\/thecloudmarathoner.com\/index.php\/2022\/03\/01\/simplifying-azure-iac-with-azure-bicep-child-resources\/","title":{"rendered":"Simplifying Azure IaC with Azure Bicep child resources"},"content":{"rendered":"\n<p>Hello Cloud Marathoners,<\/p>\n\n\n\n<p>The infrastructure-as-code (IaC) is not a just a &#8220;buzzword&#8221;, it is brought by a necessity to manage your digital estate more predictably while source-controlling the changes that are introduced over time. In its turn, this approach makes it easier to keep your workload environments compliant and saves ton of time in troubleshooting, development and auditing your resources<\/p>\n\n\n\n<p>In this post, we will look into the necessity of child resources in Azure and how Bicep language simplifies their management and declaration as a code.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"540\" src=\"\/wp-content\/uploads\/2022\/03\/image-3-1024x540.png\" alt=\"\" class=\"wp-image-1011\" srcset=\"\/wp-content\/uploads\/2022\/03\/image-3-1024x540.png 1024w, \/wp-content\/uploads\/2022\/03\/image-3-300x158.png 300w, \/wp-content\/uploads\/2022\/03\/image-3-768x405.png 768w, \/wp-content\/uploads\/2022\/03\/image-3-1200x633.png 1200w, \/wp-content\/uploads\/2022\/03\/image-3.png 1208w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">why azure bicep child resources?<\/h4>\n\n\n\n<p>There are a number of scenarios where it makes perfect sense to declare resources within the context of their parent. For example; storage blob containers could not be declared and used without a parent storage account.<\/p>\n\n\n\n<p>In addition to Blob containers, there are many other child resource types in Azure like:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Virtual network subnets<\/li><li>SQL databases<\/li><li>Azure Cosmos DB containers<\/li><li>SQL databases<\/li><li>VM extensions<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">How could you define child resources?<\/h4>\n\n\n\n<p>Unsurprisingly, there is more than one way to define Azure Bicep child resources. Each approach will depend on a specific use case that you or your team is looking forward to delivering.<\/p>\n\n\n\n<p>Further we will use the example of a storage account resource to describe different options of child resource declarations. This will make it easier to describe the concepts and available&nbsp;options to you. However, these concepts could be easily used on other  Azure services like VMs and VNets that do have child resources too.<\/p>\n\n\n\n<p>All the options and sample codes are available&nbsp;on <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/ElYusubov\/Learn-Bicep\/blob\/main\/samples\/14-deploy-child-parent-scenarios.bicep\" target=\"_blank\">Learn-Bicep GitHub repo<\/a> page.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Option-1 : Child resource created with reference to parent<\/h5>\n\n\n\n<p>Our first option is declaring a child Blob container resource as a separate&nbsp;independent resource  with a reference to a parent resource. Like, it is illustrated on the example screen-shot from the Learn-Bicep repo.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"\/wp-content\/uploads\/2022\/03\/image.png\" alt=\"\" class=\"wp-image-1005\" width=\"853\" height=\"133\" srcset=\"\/wp-content\/uploads\/2022\/03\/image.png 990w, \/wp-content\/uploads\/2022\/03\/image-300x47.png 300w, \/wp-content\/uploads\/2022\/03\/image-768x120.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure><\/div>\n\n\n\n<p><br>For this option to work, we would need to declare an Azure Storage Blob service too. Let&#8217;s look into how it could be done while considering a second option.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Option-2 : Including a child resource in the declaration<\/h5>\n\n\n\n<p>Our second option is declaring a Storage Blob service resource as a separate independent resource  with a reference to a parent Storage Account resource. Then it has an inner declaration for a container child resources within the Storage Blob service.<br><br>Let&#8217;s look at the example screen-shot from the Learn-Bicep repo.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"933\" height=\"251\" src=\"\/wp-content\/uploads\/2022\/03\/image-4.png\" alt=\"\" class=\"wp-image-1015\" srcset=\"\/wp-content\/uploads\/2022\/03\/image-4.png 933w, \/wp-content\/uploads\/2022\/03\/image-4-300x81.png 300w, \/wp-content\/uploads\/2022\/03\/image-4-768x207.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n\n\n\n<p>This option might be an ideal approach if you have few child resources in your declaration. However, it would not be the most efficient one to use, if the number of child resources you are required to deploy is in dozens, hundreds or even thousands.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Option-3 : Automation and looping with enumeration \ud83d\ude42<\/h5>\n\n\n\n<p>The final option will serve you well, if you have 100s of pre-defined containers that should be deployed into your Azure environment.<\/p>\n\n\n\n<p>By leveraging the &#8220;iterative loops&#8221; in Bicep we can easily iterate over these containers while creating them in a compact and repeatable manner, like in the following screen-shot from the repo code.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"\/wp-content\/uploads\/2022\/03\/image-2-1024x123.png\" alt=\"\" class=\"wp-image-1007\" width=\"1024\" height=\"123\" srcset=\"\/wp-content\/uploads\/2022\/03\/image-2-1024x123.png 1024w, \/wp-content\/uploads\/2022\/03\/image-2-300x36.png 300w, \/wp-content\/uploads\/2022\/03\/image-2-768x92.png 768w, \/wp-content\/uploads\/2022\/03\/image-2-1200x144.png 1200w, \/wp-content\/uploads\/2022\/03\/image-2.png 1278w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><br>Looking for more Bicep goodness?<\/h4>\n\n\n\n<p>A community of developers and engineers started a great initiative &#8211; to help everyone to <strong>learn Azure Bicep<\/strong> for #free by sharing &amp; contributing to the <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/ElYusubov\/AWESOME-Azure-Bicep\" target=\"_blank\">AWESOME-Azure-Bicep  GitHub repo<\/a>. <br><br>Please, like \u2b50  subscribe \ud83c\udf74 &amp; fork it \ud83d\udc4d  <br><a href=\"https:\/\/www.linkedin.com\/feed\/hashtag\/?keywords=sharingiscaring\">As always #SharingIsCaring<\/a> <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">summary<\/h4>\n\n\n\n<p>In this post, you have learned about three different options to declare Bicep child resources.<\/p>\n\n\n\n<p>All code samples and presented Bicep files are placed in \u201cLearn-Bicep\u201d GitHub repo \ud83d\udc49&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/ElYusubov\/Learn-Bicep\/blob\/main\/samples\/14-deploy-child-parent-scenarios.bicep\" target=\"_blank\">https:\/\/github.com\/ElYusubov\/Learn-Bicep\/blob\/main\/samples\/14-deploy-child-parent-scenarios.bicep<\/a>  \ud83d\udc4d<\/p>\n\n\n\n<p>Would you be interested in a recorded short video that demonstrates&nbsp;these capabilities ?  <\/p>\n<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_829\" class=\"pvc_stats all  \" data-element-id=\"829\" 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, The infrastructure-as-code (IaC) is not a just a &#8220;buzzword&#8221;, it is brought by a necessity to manage your digital estate more predictably while source-controlling the changes that are introduced over time. In its turn, this approach makes it easier to keep your workload environments compliant and saves ton of time in troubleshooting, &hellip; <a href=\"https:\/\/thecloudmarathoner.com\/index.php\/2022\/03\/01\/simplifying-azure-iac-with-azure-bicep-child-resources\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Simplifying Azure IaC with Azure Bicep child resources&#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],"tags":[],"class_list":["post-829","post","type-post","status-publish","format-standard","hentry","category-azure-bicep","category-infrastructure-as-code-iac"],"_links":{"self":[{"href":"https:\/\/thecloudmarathoner.com\/index.php\/wp-json\/wp\/v2\/posts\/829","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thecloudmarathoner.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thecloudmarathoner.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thecloudmarathoner.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thecloudmarathoner.com\/index.php\/wp-json\/wp\/v2\/comments?post=829"}],"version-history":[{"count":19,"href":"https:\/\/thecloudmarathoner.com\/index.php\/wp-json\/wp\/v2\/posts\/829\/revisions"}],"predecessor-version":[{"id":1022,"href":"https:\/\/thecloudmarathoner.com\/index.php\/wp-json\/wp\/v2\/posts\/829\/revisions\/1022"}],"wp:attachment":[{"href":"https:\/\/thecloudmarathoner.com\/index.php\/wp-json\/wp\/v2\/media?parent=829"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thecloudmarathoner.com\/index.php\/wp-json\/wp\/v2\/categories?post=829"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thecloudmarathoner.com\/index.php\/wp-json\/wp\/v2\/tags?post=829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}