Terraform: count, for_each, and for loops
<p>In the previous post, we got an overview of the Terraform data types — <a href="https://rtfm.co.ua/en/terraform-introduction-to-data-types-primitives-and-complex/" rel="noopener ugc nofollow" target="_blank">Terraform: introduction to data types — primitives and complex</a>.</p>
<p>Now let’s see how these types can be used in loops.</p>
<p>Terraform supports three types of cycles:</p>
<ul>
<li><code>count</code>: the simplest, used with a given number or with a function <code>length()</code>; uses indexes from a <code>list</code> or <code>map</code> for iteration</li>
<li>suitable for creating identical resources that will not change</li>
<li><code>for_each</code>: has more options, used with a <code>map</code> or <code>set</code>, uses sequence key names to iterate</li>
<li>suitable for creating resources of the same type, but with the ability to set different parameters</li>
<li><code>for</code>: used to filter and transform objects with <code>lists</code>, <code>sets</code>, <code>tuples</code> or <code>maps</code>; can be used in conjunction with operators and functions lie <code>if</code>, <code>join</code>, <code>replace</code>, <code>lower</code>, or<code>upper</code></li>
</ul>
<p><a href="https://itnext.io/terraform-count-for-each-and-for-loops-1018526c2047"><strong>Click Here</strong></a></p>