{"id":2440,"date":"2022-01-23T07:38:39","date_gmt":"2022-01-23T13:38:39","guid":{"rendered":"https:\/\/www.ciraltos.com\/?p=2440"},"modified":"2023-03-23T05:24:00","modified_gmt":"2023-03-23T10:24:00","slug":"dynamic-blocks-in-terraform-with-azure","status":"publish","type":"post","link":"https:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/","title":{"rendered":"Dynamic Blocks in Terraform with Azure"},"content":{"rendered":"\n<figure class=\"wp-block-image alignleft size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"169\" height=\"162\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2021\/12\/TerraformAzureLogo.png\" alt=\"\" class=\"wp-image-2407\"\/><\/figure>\n\n\n\n<p>Resources in Terraform are deployed as top-level resources.&nbsp; A server or App Service plan for example.&nbsp; These top-level resources include inline, or sub-resources; blocks of code that configure the top-level resource.  In this blog post and video, we use a Network Security Group (NSG) as a Dynamic block example by creating multiple security rules as inline or sub-resources.<\/p>\n\n\n\n<!--more-->\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"ast-oembed-container\" style=\"height: 100%;\"><iframe loading=\"lazy\" title=\"Dynamic Blocks in Terraform with Azure\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/gL7FIUPvsXI?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe><\/div>\n<\/div><\/figure>\n\n\n\n<p>Typically, inline recourse requires multiple configuration settings.&nbsp; We could create multiple copies of the inline resource when more than one is needed. We&#8217;ll stick with the Network Security Group (NSG) for this example.&nbsp; An NSG will likely contain more than one security rule, and creating a copy of each rule will limit the code&#8217;s portability and use in a module.&nbsp; <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"908\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2022\/01\/Multiple-Security-Rules-1024x908.jpg\" alt=\"\" class=\"wp-image-2441\" srcset=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Multiple-Security-Rules-1024x908.jpg 1024w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Multiple-Security-Rules-300x266.jpg 300w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Multiple-Security-Rules-768x681.jpg 768w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Multiple-Security-Rules.jpg 1455w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\"> Multiple Security Rules <\/figcaption><\/figure>\n\n\n\n<p>We may want three rules for one deployment and 10 for the\nother.&nbsp; So how do we make an inline, or\nsub-resource dynamic?&nbsp; That is what\nDynamic blocks are for.&nbsp; A Dynamic block uses\na for_each loop to create multiple copies of a sub-resource nested inside a\nresource block.&nbsp; It makes repeatable,\nnested blocks in the parent resource argument.<\/p>\n\n\n\n<p>Dynamic blocks can be used for Resource, Data, Provider, and\nProvisioner blocks.&nbsp; They can also be\nnested inside other dynamic blocks but use nesting sparingly.&nbsp; Nesting multiple levels makes the code\ndifficult to read.<\/p>\n\n\n\n<p>The example below creates a Network Security Group with multiple security rules using the dynamic block.&nbsp; The code used for this example can be found here <a href=\"https:\/\/github.com\/tsrob50\/TerraformExamples\/tree\/main\/DynamicNSG\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"https:\/\/github.com\/tsrob50\/TerraformExamples\/tree\/main\/DynamicNSG (opens in a new tab)\">https:\/\/github.com\/tsrob50\/TerraformExamples\/tree\/main\/DynamicNSG<\/a><\/p>\n\n\n\n<h1>Create the Dynamic Block<\/h1>\n\n\n\n<p>Below is the default configuration for an NSG and a single security rule. This is the example from the AzureRM resource at <a href=\"https:\/\/registry.terraform.io\/providers\/hashicorp\/azurerm\/latest\/docs\/resources\/network_security_group\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"https:\/\/registry.terraform.io\/providers\/hashicorp\/azurerm\/latest\/docs\/resources\/network_security_group (opens in a new tab)\">https:\/\/registry.terraform.io\/providers\/hashicorp\/azurerm\/latest\/docs\/resources\/network_security_group<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"724\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2022\/01\/Starting-NSG-1024x724.jpg\" alt=\"\" class=\"wp-image-2442\" srcset=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Starting-NSG-1024x724.jpg 1024w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Starting-NSG-300x212.jpg 300w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Starting-NSG-768x543.jpg 768w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Starting-NSG.jpg 1285w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\"> Starting NSG <\/figcaption><\/figure>\n\n\n\n<p>Let\u2019s turn the Security Rule section into a dynamic\nblock.&nbsp; Start by adding <em>dynamic<\/em> in\nfront of <em>security_rule<\/em>, then add double quotes around <em>security_rule.<\/em><\/p>\n\n\n\n<p>One item to note, <em>security_rule\u00ad<\/em> is an inline\nresource that the NSG expects to see at the time of deployment. It is not an\narbitrary local name, it has to be called <em>security_rule<\/em>.<\/p>\n\n\n\n<p>Next, we need to add a <em>for_each<\/em> loop in the dynamic\nblock.&nbsp; For_each provides the looping\nfunctionality for the block.&nbsp; Add \u2018<em>for\u00ad_each\u00ad<\/em>\n=\u2019 in the dynamic block.&nbsp; Shown below are\nthe changes so far.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"599\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2022\/01\/for_each-1024x599.jpg\" alt=\"\" class=\"wp-image-2443\" srcset=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/for_each-1024x599.jpg 1024w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/for_each-300x176.jpg 300w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/for_each-768x449.jpg 768w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/for_each.jpg 1410w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\"> for_each<\/figcaption><\/figure>\n\n\n\n<h1>Variable Type List<\/h1>\n\n\n\n<p>The use of a <em>for_each<\/em> loop implies a list of items to\nloop through.&nbsp; Let\u2019s move over to the <em>variable.tf<\/em>\nfile and create a list of variables.&nbsp; The\nexample below uses the variable type <em>list<\/em> to create a collection object\nwith all the expected variables.&nbsp; Each\nitem in the list represents one security rule.&nbsp;\nWith a list, we can add one, five, or ten rules to the list and each one\nwill be added with the Dynamic block.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"591\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2022\/01\/Variable-List-Object-1024x591.jpg\" alt=\"\" class=\"wp-image-2444\" srcset=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Variable-List-Object-1024x591.jpg 1024w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Variable-List-Object-300x173.jpg 300w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Variable-List-Object-768x444.jpg 768w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Variable-List-Object.jpg 1108w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\"> Variable List Object <\/figcaption><\/figure>\n\n\n\n<p>IMAGE Variable List Object<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>It is possible to use the type of list without the object.&nbsp; Using an object with a list of values allows for input validation and makes the code easier to read.<\/p>\n<\/blockquote>\n\n\n\n<h1>terraform.tfvars Example<\/h1>\n\n\n\n<p>Now that we have the variable let\u2019s move on to providing\nvalues for the deployment.&nbsp; The section\nof the <em>terraform.tfvars<\/em> file below shows the value supplied for the <em>nsg_rules<\/em>\nvariable.&nbsp; The square brackets []\nindicate a list of items.&nbsp; Each item in\nthe list provides the value for a security rule.&nbsp; Deploying this example will create an NSG\nwith three rules.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"706\" height=\"1024\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2022\/01\/Security-Rules-706x1024.jpg\" alt=\"\" class=\"wp-image-2445\" srcset=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Security-Rules-706x1024.jpg 706w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Security-Rules-207x300.jpg 207w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Security-Rules-768x1114.jpg 768w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Security-Rules-1059x1536.jpg 1059w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Security-Rules.jpg 1101w\" sizes=\"(max-width: 706px) 100vw, 706px\" \/><figcaption class=\"wp-element-caption\"> Security Rules <\/figcaption><\/figure>\n\n\n\n<h1>Create the Dynamic Block Continued<\/h1>\n\n\n\n<p>Now that we have the variables in place, let\u2019s get back to\ncreating the dynamic block.&nbsp; We set the <em>for_each<\/em>\nloop in the dynamic block, let\u2019s set it to equal the <em>nsg_rules<\/em> variable.\n<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"972\" height=\"171\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2022\/01\/nsg_rules-Variable.jpg\" alt=\"\" class=\"wp-image-2446\" srcset=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/nsg_rules-Variable.jpg 972w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/nsg_rules-Variable-300x53.jpg 300w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/nsg_rules-Variable-768x135.jpg 768w\" sizes=\"(max-width: 972px) 100vw, 972px\" \/><figcaption class=\"wp-element-caption\"> nsg_rules Variable <\/figcaption><\/figure>\n\n\n\n<p>When we deploy a resource with a dynamic block, it creates\nmultiple inline resource blocks, one for each item supplied by the list of variables.&nbsp; We need to specify the content that makes up\neach item next.&nbsp; We do that by putting\nthe arguments in a <em>content<\/em> block.&nbsp;\nAdd <em>content<\/em> on the line under the <em>for_each<\/em> and wrap the arguments\nin squiggly brackets as shown below.&nbsp;\nDon\u2019t forget the closing bracket.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1018\" height=\"640\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2022\/01\/Content-Block.jpg\" alt=\"\" class=\"wp-image-2447\" srcset=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Content-Block.jpg 1018w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Content-Block-300x189.jpg 300w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Content-Block-768x483.jpg 768w\" sizes=\"(max-width: 1018px) 100vw, 1018px\" \/><figcaption class=\"wp-element-caption\"> Content Block<\/figcaption><\/figure>\n\n\n\n<p>At this point, the dynamic block will loop through each item\nin the list of variables and use the values to create the security rules.&nbsp; Currently, the example uses hardcoded values.&nbsp; We specify to use the value from the variable\nby changing the arguments to <em>security_rule.value<\/em>, then specifying the\nvalue by putting the value name in double quotes and square brackets <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">name = security_rule.value[\u201cname\u201d]<\/pre>\n\n\n\n<p>Once finished, the dynamic block will look similar to below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"565\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2022\/01\/Finished-Dynamic-Block-1024x565.jpg\" alt=\"\" class=\"wp-image-2448\" srcset=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Finished-Dynamic-Block-1024x565.jpg 1024w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Finished-Dynamic-Block-300x165.jpg 300w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Finished-Dynamic-Block-768x424.jpg 768w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Finished-Dynamic-Block-1536x847.jpg 1536w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Finished-Dynamic-Block.jpg 1742w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\"> Finished Dynamic Block<\/figcaption><\/figure>\n\n\n\n<p>Save the files and run <em>terraform init <\/em>and <em>terraform\nplan<\/em>.&nbsp; The output from the plan shows\nthree rules are added to the NSG.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"930\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2022\/01\/Terraform-Plan-1024x930.jpg\" alt=\"\" class=\"wp-image-2449\" srcset=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Terraform-Plan-1024x930.jpg 1024w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Terraform-Plan-300x273.jpg 300w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Terraform-Plan-768x698.jpg 768w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2022\/01\/Terraform-Plan.jpg 1299w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\"> Terraform Plan <\/figcaption><\/figure>\n\n\n\n<p>That is how to use dynamic blocks in Terraform with Azure.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Resources in Terraform are deployed as top-level resources.&nbsp; A server or App Service plan for example.&nbsp; These top-level resources include inline, or sub-resources; blocks of code that configure the top-level resource. In this blog post and video, we use a Network Security Group (NSG) as a Dynamic block example by creating multiple security rules as &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/\"> <span class=\"screen-reader-text\">Dynamic Blocks in Terraform with Azure<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":2407,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[1159],"tags":[1163,9,992,1212,1214,1189,1164,1169,1174,37,1172,1213,1160,1165,1170,1186,1175,1215,1184,1171,1162,1185,1179,1178,1177,1183,1168,1216,962,268],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Dynamic Blocks in Terraform with Azure - ciraltos<\/title>\n<meta name=\"description\" content=\"In this blog post and video, we use a Network Security Group (NSG) as a Dynamic block example by creating multiple security rules as inline or sub-resources.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dynamic Blocks in Terraform with Azure - ciraltos\" \/>\n<meta property=\"og:description\" content=\"In this blog post and video, we use a Network Security Group (NSG) as a Dynamic block example by creating multiple security rules as inline or sub-resources.\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/\" \/>\n<meta property=\"og:site_name\" content=\"ciraltos\" \/>\n<meta property=\"article:published_time\" content=\"2022-01-23T13:38:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-23T10:24:00+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/TerraformAzureLogo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"169\" \/>\n\t<meta property=\"og:image:height\" content=\"162\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Travis Roberts\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ciraltos\" \/>\n<meta name=\"twitter:site\" content=\"@ciraltos\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Travis Roberts\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/\"},\"author\":{\"name\":\"Travis Roberts\",\"@id\":\"http:\/\/www.ciraltos.com\/staging2\/#\/schema\/person\/25391996d6cddfecd4d257162b7e373a\"},\"headline\":\"Dynamic Blocks in Terraform with Azure\",\"datePublished\":\"2022-01-23T13:38:39+00:00\",\"dateModified\":\"2023-03-23T10:24:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/\"},\"wordCount\":857,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/www.ciraltos.com\/staging2\/#\/schema\/person\/25391996d6cddfecd4d257162b7e373a\"},\"keywords\":[\".tf\",\"Azure\",\"Azure CLI\",\"Dynamic Block\",\"dynamic block example\",\"For_each\",\"HashiCorp\",\"IaC Terraform\",\"main.tf\",\"NSG\",\"registry\",\"Security Rule\",\"Terraform\",\"Terraform Apply\",\"Terraform Destroy\",\"Terraform Examples\",\"Terraform for Azure\",\"Terraform list\",\"terraform modules\",\"Terraform Plan\",\"terraform registry\",\"Terraform Resource\",\"terraform training\",\"terraform tutorial\",\"terraform var\",\"terraform variables\",\"Terraform Write\",\"terraform.tfstate Azure\",\"VSCode\",\"workflow\"],\"articleSection\":[\"Terraform\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/\",\"url\":\"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/\",\"name\":\"Dynamic Blocks in Terraform with Azure - ciraltos\",\"isPartOf\":{\"@id\":\"http:\/\/www.ciraltos.com\/staging2\/#website\"},\"datePublished\":\"2022-01-23T13:38:39+00:00\",\"dateModified\":\"2023-03-23T10:24:00+00:00\",\"description\":\"In this blog post and video, we use a Network Security Group (NSG) as a Dynamic block example by creating multiple security rules as inline or sub-resources.\",\"breadcrumb\":{\"@id\":\"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/www.ciraltos.com\/staging2\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Dynamic Blocks in Terraform with Azure\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.ciraltos.com\/staging2\/#website\",\"url\":\"http:\/\/www.ciraltos.com\/staging2\/\",\"name\":\"ciraltos\",\"description\":\"cloud, technology and trends\",\"publisher\":{\"@id\":\"http:\/\/www.ciraltos.com\/staging2\/#\/schema\/person\/25391996d6cddfecd4d257162b7e373a\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.ciraltos.com\/staging2\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/www.ciraltos.com\/staging2\/#\/schema\/person\/25391996d6cddfecd4d257162b7e373a\",\"name\":\"Travis Roberts\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.ciraltos.com\/staging2\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2023\/03\/Logo-1.png\",\"contentUrl\":\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2023\/03\/Logo-1.png\",\"width\":5657,\"height\":3563,\"caption\":\"Travis Roberts\"},\"logo\":{\"@id\":\"http:\/\/www.ciraltos.com\/staging2\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/www.ciraltos.com\",\"https:\/\/twitter.com\/ciraltos\"],\"url\":\"https:\/\/www.ciraltos.com\/staging2\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Dynamic Blocks in Terraform with Azure - ciraltos","description":"In this blog post and video, we use a Network Security Group (NSG) as a Dynamic block example by creating multiple security rules as inline or sub-resources.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/","og_locale":"en_US","og_type":"article","og_title":"Dynamic Blocks in Terraform with Azure - ciraltos","og_description":"In this blog post and video, we use a Network Security Group (NSG) as a Dynamic block example by creating multiple security rules as inline or sub-resources.","og_url":"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/","og_site_name":"ciraltos","article_published_time":"2022-01-23T13:38:39+00:00","article_modified_time":"2023-03-23T10:24:00+00:00","og_image":[{"width":169,"height":162,"url":"http:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/TerraformAzureLogo.png","type":"image\/png"}],"author":"Travis Roberts","twitter_card":"summary_large_image","twitter_creator":"@ciraltos","twitter_site":"@ciraltos","twitter_misc":{"Written by":"Travis Roberts","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/#article","isPartOf":{"@id":"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/"},"author":{"name":"Travis Roberts","@id":"http:\/\/www.ciraltos.com\/staging2\/#\/schema\/person\/25391996d6cddfecd4d257162b7e373a"},"headline":"Dynamic Blocks in Terraform with Azure","datePublished":"2022-01-23T13:38:39+00:00","dateModified":"2023-03-23T10:24:00+00:00","mainEntityOfPage":{"@id":"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/"},"wordCount":857,"commentCount":0,"publisher":{"@id":"http:\/\/www.ciraltos.com\/staging2\/#\/schema\/person\/25391996d6cddfecd4d257162b7e373a"},"keywords":[".tf","Azure","Azure CLI","Dynamic Block","dynamic block example","For_each","HashiCorp","IaC Terraform","main.tf","NSG","registry","Security Rule","Terraform","Terraform Apply","Terraform Destroy","Terraform Examples","Terraform for Azure","Terraform list","terraform modules","Terraform Plan","terraform registry","Terraform Resource","terraform training","terraform tutorial","terraform var","terraform variables","Terraform Write","terraform.tfstate Azure","VSCode","workflow"],"articleSection":["Terraform"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/#respond"]}]},{"@type":"WebPage","@id":"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/","url":"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/","name":"Dynamic Blocks in Terraform with Azure - ciraltos","isPartOf":{"@id":"http:\/\/www.ciraltos.com\/staging2\/#website"},"datePublished":"2022-01-23T13:38:39+00:00","dateModified":"2023-03-23T10:24:00+00:00","description":"In this blog post and video, we use a Network Security Group (NSG) as a Dynamic block example by creating multiple security rules as inline or sub-resources.","breadcrumb":{"@id":"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.ciraltos.com\/staging2\/dynamic-blocks-in-terraform-with-azure\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/www.ciraltos.com\/staging2\/"},{"@type":"ListItem","position":2,"name":"Dynamic Blocks in Terraform with Azure"}]},{"@type":"WebSite","@id":"http:\/\/www.ciraltos.com\/staging2\/#website","url":"http:\/\/www.ciraltos.com\/staging2\/","name":"ciraltos","description":"cloud, technology and trends","publisher":{"@id":"http:\/\/www.ciraltos.com\/staging2\/#\/schema\/person\/25391996d6cddfecd4d257162b7e373a"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.ciraltos.com\/staging2\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"http:\/\/www.ciraltos.com\/staging2\/#\/schema\/person\/25391996d6cddfecd4d257162b7e373a","name":"Travis Roberts","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.ciraltos.com\/staging2\/#\/schema\/person\/image\/","url":"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2023\/03\/Logo-1.png","contentUrl":"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2023\/03\/Logo-1.png","width":5657,"height":3563,"caption":"Travis Roberts"},"logo":{"@id":"http:\/\/www.ciraltos.com\/staging2\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/www.ciraltos.com","https:\/\/twitter.com\/ciraltos"],"url":"https:\/\/www.ciraltos.com\/staging2\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.ciraltos.com\/staging2\/wp-json\/wp\/v2\/posts\/2440"}],"collection":[{"href":"https:\/\/www.ciraltos.com\/staging2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ciraltos.com\/staging2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ciraltos.com\/staging2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ciraltos.com\/staging2\/wp-json\/wp\/v2\/comments?post=2440"}],"version-history":[{"count":6,"href":"https:\/\/www.ciraltos.com\/staging2\/wp-json\/wp\/v2\/posts\/2440\/revisions"}],"predecessor-version":[{"id":3785,"href":"https:\/\/www.ciraltos.com\/staging2\/wp-json\/wp\/v2\/posts\/2440\/revisions\/3785"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ciraltos.com\/staging2\/wp-json\/wp\/v2\/media\/2407"}],"wp:attachment":[{"href":"https:\/\/www.ciraltos.com\/staging2\/wp-json\/wp\/v2\/media?parent=2440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ciraltos.com\/staging2\/wp-json\/wp\/v2\/categories?post=2440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ciraltos.com\/staging2\/wp-json\/wp\/v2\/tags?post=2440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}