{"id":2394,"date":"2021-12-26T12:52:36","date_gmt":"2021-12-26T18:52:36","guid":{"rendered":"https:\/\/www.ciraltos.com\/?p=2394"},"modified":"2023-03-23T05:31:31","modified_gmt":"2023-03-23T10:31:31","slug":"use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host","status":"publish","type":"post","link":"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/","title":{"rendered":"Use For_Each in a Terraform Module with Azure VNets and Bastion Host"},"content":{"rendered":"\n<figure class=\"wp-block-image alignleft size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"176\" height=\"186\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2021\/11\/Terraform_VerticalLogo_Color_RGB-2.png\" alt=\"\" class=\"wp-image-2303\"\/><\/figure>\n\n\n\n<p>You have laded on another post and video in a series on Terraform and Azure.&nbsp; This post and accompanying video looks at a more complicated module example that uses a looping function to create multiple, similar resources.&nbsp; The example uses Terraform to create an Azure Bastion Host and VNet with multiple subnets in Azure.&nbsp; <\/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=\"Using For_Each in a Terraform Module with Azure VNets and Bastion Host\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/RsDgtUZAugA?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>Check out other posts and videos in the series located here:<br><a rel=\"noreferrer noopener\" aria-label=\"Getting Started with Terraform and Azure (opens in a new tab)\" href=\"https:\/\/www.ciraltos.com\/getting-started-with-terraform-and-azure-overview-and-setup\/\" target=\"_blank\">Getting Started with Terraform and Azure<\/a><br><a rel=\"noreferrer noopener\" aria-label=\"Terraform Workflow with Azure (opens in a new tab)\" href=\"https:\/\/www.ciraltos.com\/terraform-workflow-with-azure-write-plan-and-apply\/\" target=\"_blank\">Terraform Workflow with Azure<\/a><br><a rel=\"noreferrer noopener\" aria-label=\"Input Variables with Terraform and Azure (opens in a new tab)\" href=\"https:\/\/www.ciraltos.com\/input-variables-with-terraform-and-azure\/\" target=\"_blank\">Input Variables with Terraform and Azure<\/a><br><a rel=\"noreferrer noopener\" aria-label=\"Modules and Outputs with Terraform and Azure (opens in a new tab)\" href=\"https:\/\/www.ciraltos.com\/modules-and-outputs-with-terraform-and-azure\/\" target=\"_blank\">Modules and Outputs with Terraform and Azure<\/a><\/p>\n\n\n\n<p>The code used below can be found on GitHub here:<br><a href=\"https:\/\/github.com\/tsrob50\/TerraformExamples\/tree\/main\/VNetandBastionHost\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"https:\/\/github.com\/tsrob50\/TerraformExamples\/tree\/main\/VNetandBastionHost (opens in a new tab)\">https:\/\/github.com\/tsrob50\/TerraformExamples\/tree\/main\/VNetandBastionHost<\/a><\/p>\n\n\n\n<h1>For_Each<\/h1>\n\n\n\n<p>The goal with creating this module is to make it reusable\nfor different projects. For example, one project may only need one subnet, while\nanother may need several.&nbsp; Each subnet in\na VNet is similar to the others, except for the subnet name and IP Address\nPrefix.&nbsp; <\/p>\n\n\n\n<p>A \u201cfor_each\u201d block creates multiple Subnets on the VNet.&nbsp; We provide a map of subnet names and IP\naddress prefixes, and for each set, the <em>for_each<\/em> argument in the resource\nblock creates a subnet.<\/p>\n\n\n\n<h1>Map vs. List<\/h1>\n\n\n\n<p>A map in Terraform is a list of key, value pairs.&nbsp; For example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">subnet_1 = {<br>&nbsp; name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;= \"subnet_1\"<br>&nbsp; address_prefixes = [\"10.13.1.0\/24\"]<br>}<\/pre>\n\n\n\n<p>Subnet_1 in the above example contains both the subnet name\nand the IP address prefix.<\/p>\n\n\n\n<p>A list in Terraform contains a sequence of values, such as:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[\u201cred\u201d, \u201dgreen\u201d, \u201dblue\u201d]<\/pre>\n\n\n\n<p>We used a map for the subnets in the example that follows.<\/p>\n\n\n\n<h1>The Module<\/h1>\n\n\n\n<p>We went over the Terraform workflow, and created modules in\nother videos, links to those are at the top of this post.&nbsp; For the following, we are going to skip to\nthe relevant information.&nbsp; Below is the resource\nblock for the subnets.&nbsp; Notice the resource\ngroup name and virtual network name use a variable and resource block.&nbsp; These are the same for each subnet.&nbsp; The subnet name and address prefix will be different.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"654\" height=\"188\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2021\/12\/Subnet-Resouce.png\" alt=\"\" class=\"wp-image-2395\" srcset=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/Subnet-Resouce.png 654w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/Subnet-Resouce-300x86.png 300w\" sizes=\"(max-width: 654px) 100vw, 654px\" \/><figcaption class=\"wp-element-caption\"> Subnet Resource <\/figcaption><\/figure>\n\n\n\n<p>We need to add the values for the name and prefix. But, first,\nlet\u2019s create a variable block for the subnets.<\/p>\n\n\n\n<h1>Subnet Variable<\/h1>\n\n\n\n<p>We added three subnets as default values to the variable for\nthe example below.&nbsp; The example is a map\nof key, value pairs that include the name and prefix for each subnet.&nbsp; <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"526\" height=\"422\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2021\/12\/Subnet-Variable.png\" alt=\"\" class=\"wp-image-2396\" srcset=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/Subnet-Variable.png 526w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/Subnet-Variable-300x241.png 300w\" sizes=\"(max-width: 526px) 100vw, 526px\" \/><figcaption class=\"wp-element-caption\"> Subnet Variable <\/figcaption><\/figure>\n\n\n\n<p>The image above is missing one rather important subnet, the Azure\nBastion Host subnet.&nbsp; An Azure Bastion subnet\nmust have the name \u201cAzureBastionSubnet\u201d and have an address space of \/26 or larger.&nbsp; Azure Bastion manages the Network Security\nGroups and other settings on the subnet and because of that, the subnet is\ndedicated to Azure Bastion.&nbsp; Let\u2019s add\nthat as the Bastion Host subnet in the subnets variable.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"543\" height=\"525\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2021\/12\/Bastion-Subnet.png\" alt=\"\" class=\"wp-image-2397\" srcset=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/Bastion-Subnet.png 543w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/Bastion-Subnet-300x290.png 300w\" sizes=\"(max-width: 543px) 100vw, 543px\" \/><figcaption class=\"wp-element-caption\"> Bastion Subnet <\/figcaption><\/figure>\n\n\n\n<h1>Looping a Resource<\/h1>\n\n\n\n<p>Now that we have defaults set for the variable, we can\nfinish the resource block for the subnets.&nbsp;\nWe start by adding <em>for_each<\/em> as the first argument in the resource\nblock.&nbsp; The <em>for_each<\/em> statement needs\na value, what value to use for the resource.&nbsp;\nIn this example, the loop will use the variable <em>var.subnets<\/em>, looping\nthrough each value in the variable.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"645\" height=\"199\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2021\/12\/For_Each-Argument.png\" alt=\"\" class=\"wp-image-2398\" srcset=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/For_Each-Argument.png 645w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/For_Each-Argument-300x93.png 300w\" sizes=\"(max-width: 645px) 100vw, 645px\" \/><figcaption class=\"wp-element-caption\"> For_Each Argument <\/figcaption><\/figure>\n\n\n\n<p>Next, we need to provide the values for <em>name<\/em> and <em>address_prefixes<\/em>.&nbsp; The loop will use each instance of those values\nto build the four subnets.&nbsp; We can call\nthese values with <em>each.value<\/em> followed by the name of the value in square\nbrackets.&nbsp; For example, below is what is\nentered to add the network name.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">name &nbsp;= each.value[\u201cname\u201d]<\/pre>\n\n\n\n<p>once finished, the resource block for the subnets will look\nlike the image below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"673\" height=\"178\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2021\/12\/For_Each-Subnet-Resource-Block.png\" alt=\"\" class=\"wp-image-2399\" srcset=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/For_Each-Subnet-Resource-Block.png 673w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/For_Each-Subnet-Resource-Block-300x79.png 300w\" sizes=\"(max-width: 673px) 100vw, 673px\" \/><figcaption class=\"wp-element-caption\"> For_Each Subnet Resource Block <\/figcaption><\/figure>\n\n\n\n<p>The deployment will loop through each subnet and apply the\nname and address prefix for that subnet.&nbsp;\n<\/p>\n\n\n\n<h1>Looping Output<\/h1>\n\n\n\n<p>Now that we can create multiple subnets, we may want to output\nvalues from those subnets.&nbsp; For this\nexample, we will output the subnet ID for each subnet.<\/p>\n\n\n\n<p>From the <em>ouputs.tf<\/em> file, create a new output block\ncalled <em>azure_subent_id,<\/em> and start by adding a value.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"347\" height=\"131\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2021\/12\/Subnet-Output.png\" alt=\"\" class=\"wp-image-2400\" srcset=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/Subnet-Output.png 347w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/Subnet-Output-300x113.png 300w\" sizes=\"(max-width: 347px) 100vw, 347px\" \/><figcaption class=\"wp-element-caption\"> Subnet Output <\/figcaption><\/figure>\n\n\n\n<p>Next, we add an expression.&nbsp;\nWe can\u2019t simply reference the subnet resource block because there are\nfour different items in that block. Instead, we create an expression that loops\nthrough each item, outputting the subnet ID.&nbsp;\nWe will use a <em>for<\/em> expression to output the data.<\/p>\n\n\n\n<p>## The brackets determine the data type in a <em>for<\/em>\nexpression.&nbsp; The squiggly bracket\nindicates an object\/map.&nbsp; Objects also\nrequire a separator \u201c=&gt;\u201d between the key, value pair.&nbsp; Square brackets return a tuple\/list data type.\n<\/p>\n\n\n\n<p>Start with the <em>for<\/em> statement followed by a\nplaceholder for the given iteration of the loop.&nbsp; Then, provide the value to loop.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{ for n in keys(var.map) }<\/pre>\n\n\n\n<p>After that, add a colon <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{ for n in keys(var.map) : }<\/pre>\n\n\n\n<p>Next, provide the key and the value to return for that\nkey.&nbsp; Use the \u201c=&gt;\u201d as a separator for\nthe key, value pair.&nbsp; Use the square bracket\nat the end to indicate the key of the data to be returned. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{ for n in keys(var.map) : n =&gt; resouce.name[n]}<\/pre>\n\n\n\n<p>The final output for the subnet ID\u2019s in this example looks\nlike below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"791\" height=\"172\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2021\/12\/Subnet-For-Expression.png\" alt=\"\" class=\"wp-image-2401\" srcset=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/Subnet-For-Expression.png 791w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/Subnet-For-Expression-300x65.png 300w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/Subnet-For-Expression-768x167.png 768w\" sizes=\"(max-width: 791px) 100vw, 791px\" \/><figcaption class=\"wp-element-caption\"> Subnet For Expression <\/figcaption><\/figure>\n\n\n\n<p>This statement loops through each key in <em>var.subnet<\/em>\nand assigns it to <em>id.<\/em>&nbsp; After that,\nthe <em>id<\/em> and the subnet Id for each [id] is returned.<\/p>\n\n\n\n<p>Below are the results once the module is completed and applied.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"279\" src=\"https:\/\/www.ciraltos.com\/wp-content\/uploads\/2021\/12\/Module-Output-1024x279.png\" alt=\"\" class=\"wp-image-2402\" srcset=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/Module-Output-1024x279.png 1024w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/Module-Output-300x82.png 300w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/Module-Output-768x209.png 768w, https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/12\/Module-Output.png 1124w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\"> Module Output <\/figcaption><\/figure>\n\n\n\n<p>And that, my friends, is how to use <em>for_each<\/em> with\nTerraform.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You have laded on another post and video in a series on Terraform and Azure.&nbsp; This post and accompanying video looks at a more complicated module example that uses a looping function to create multiple, similar resources.&nbsp; The example uses Terraform to create an Azure Bastion Host and VNet with multiple subnets in Azure.&nbsp;<\/p>\n","protected":false},"author":1,"featured_media":2303,"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,1190,1189,1164,1169,1174,1181,1182,1188,1172,1160,1165,1170,1175,1184,1187,1171,1162,1185,1179,1178,1177,1183,1168,1176,1007,962,1173],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Use For_Each in a Terraform Module with Azure VNets and Bastion Host - ciraltos<\/title>\n<meta name=\"description\" content=\"This post and video looks at a complicated module example that uses a looping function to create multiple, similar resources.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Use For_Each in a Terraform Module with Azure VNets and Bastion Host - ciraltos\" \/>\n<meta property=\"og:description\" content=\"This post and video looks at a complicated module example that uses a looping function to create multiple, similar resources.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/\" \/>\n<meta property=\"og:site_name\" content=\"ciraltos\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-26T18:52:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-23T10:31:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/11\/Terraform_VerticalLogo_Color_RGB-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"176\" \/>\n\t<meta property=\"og:image:height\" content=\"186\" \/>\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\":\"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/\"},\"author\":{\"name\":\"Travis Roberts\",\"@id\":\"http:\/\/www.ciraltos.com\/staging2\/#\/schema\/person\/25391996d6cddfecd4d257162b7e373a\"},\"headline\":\"Use For_Each in a Terraform Module with Azure VNets and Bastion Host\",\"datePublished\":\"2021-12-26T18:52:36+00:00\",\"dateModified\":\"2023-03-23T10:31:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/\"},\"wordCount\":934,\"commentCount\":3,\"publisher\":{\"@id\":\"http:\/\/www.ciraltos.com\/staging2\/#\/schema\/person\/25391996d6cddfecd4d257162b7e373a\"},\"keywords\":[\".tf\",\"Azure\",\"Azure CLI\",\"for each\",\"For_each\",\"HashiCorp\",\"IaC Terraform\",\"main.tf\",\"Modules\",\"outputs\",\"outputs.tf\",\"registry\",\"Terraform\",\"Terraform Apply\",\"Terraform Destroy\",\"Terraform for Azure\",\"terraform modules\",\"terraform outputs\",\"Terraform Plan\",\"terraform registry\",\"Terraform Resource\",\"terraform training\",\"terraform tutorial\",\"terraform var\",\"terraform variables\",\"Terraform Write\",\"Terraform.tfvars\",\"Variables\",\"VSCode\",\"workdlow\"],\"articleSection\":[\"Terraform\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/\",\"url\":\"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/\",\"name\":\"Use For_Each in a Terraform Module with Azure VNets and Bastion Host - ciraltos\",\"isPartOf\":{\"@id\":\"http:\/\/www.ciraltos.com\/staging2\/#website\"},\"datePublished\":\"2021-12-26T18:52:36+00:00\",\"dateModified\":\"2023-03-23T10:31:31+00:00\",\"description\":\"This post and video looks at a complicated module example that uses a looping function to create multiple, similar resources.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/www.ciraltos.com\/staging2\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Use For_Each in a Terraform Module with Azure VNets and Bastion Host\"}]},{\"@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":"Use For_Each in a Terraform Module with Azure VNets and Bastion Host - ciraltos","description":"This post and video looks at a complicated module example that uses a looping function to create multiple, similar 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":"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/","og_locale":"en_US","og_type":"article","og_title":"Use For_Each in a Terraform Module with Azure VNets and Bastion Host - ciraltos","og_description":"This post and video looks at a complicated module example that uses a looping function to create multiple, similar resources.","og_url":"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/","og_site_name":"ciraltos","article_published_time":"2021-12-26T18:52:36+00:00","article_modified_time":"2023-03-23T10:31:31+00:00","og_image":[{"width":176,"height":186,"url":"https:\/\/www.ciraltos.com\/staging2\/wp-content\/uploads\/2021\/11\/Terraform_VerticalLogo_Color_RGB-2.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":"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/#article","isPartOf":{"@id":"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/"},"author":{"name":"Travis Roberts","@id":"http:\/\/www.ciraltos.com\/staging2\/#\/schema\/person\/25391996d6cddfecd4d257162b7e373a"},"headline":"Use For_Each in a Terraform Module with Azure VNets and Bastion Host","datePublished":"2021-12-26T18:52:36+00:00","dateModified":"2023-03-23T10:31:31+00:00","mainEntityOfPage":{"@id":"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/"},"wordCount":934,"commentCount":3,"publisher":{"@id":"http:\/\/www.ciraltos.com\/staging2\/#\/schema\/person\/25391996d6cddfecd4d257162b7e373a"},"keywords":[".tf","Azure","Azure CLI","for each","For_each","HashiCorp","IaC Terraform","main.tf","Modules","outputs","outputs.tf","registry","Terraform","Terraform Apply","Terraform Destroy","Terraform for Azure","terraform modules","terraform outputs","Terraform Plan","terraform registry","Terraform Resource","terraform training","terraform tutorial","terraform var","terraform variables","Terraform Write","Terraform.tfvars","Variables","VSCode","workdlow"],"articleSection":["Terraform"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/","url":"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/","name":"Use For_Each in a Terraform Module with Azure VNets and Bastion Host - ciraltos","isPartOf":{"@id":"http:\/\/www.ciraltos.com\/staging2\/#website"},"datePublished":"2021-12-26T18:52:36+00:00","dateModified":"2023-03-23T10:31:31+00:00","description":"This post and video looks at a complicated module example that uses a looping function to create multiple, similar resources.","breadcrumb":{"@id":"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.ciraltos.com\/staging2\/use-for_each-in-a-terraform-module-with-azure-vnets-and-bastion-host\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/www.ciraltos.com\/staging2\/"},{"@type":"ListItem","position":2,"name":"Use For_Each in a Terraform Module with Azure VNets and Bastion Host"}]},{"@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\/2394"}],"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=2394"}],"version-history":[{"count":3,"href":"https:\/\/www.ciraltos.com\/staging2\/wp-json\/wp\/v2\/posts\/2394\/revisions"}],"predecessor-version":[{"id":3794,"href":"https:\/\/www.ciraltos.com\/staging2\/wp-json\/wp\/v2\/posts\/2394\/revisions\/3794"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ciraltos.com\/staging2\/wp-json\/wp\/v2\/media\/2303"}],"wp:attachment":[{"href":"https:\/\/www.ciraltos.com\/staging2\/wp-json\/wp\/v2\/media?parent=2394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ciraltos.com\/staging2\/wp-json\/wp\/v2\/categories?post=2394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ciraltos.com\/staging2\/wp-json\/wp\/v2\/tags?post=2394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}