From the course: Advanced Terraform
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Looping with count - Terraform Tutorial
From the course: Advanced Terraform
Looping with count
- [Instructor] If you're familiar with any programming language you may have worked with loops. Loops repeat a set of instructions. Loops simplify code by reducing repetition and reducing the number of lines necessary to perform an action. Some loops use a simple numerical counter. Other loops iterate over a collection of items. Terraform and the HashiCorp Configuration Language support both these types of loops. We have three nearly identical compute instances in this configuration, so let's use a loop to cut it down to size. The only thing that differs between our three web servers are their names, which follow a web number convention, web1, web2, and web3. We can easily shorten this using the count meta-argument. First, let's run a quick check to make sure you don't have any instances deployed. In your terminal execute gcloud compute instances list. You should see listed zero items. If you have instances from a…
Contents
-
-
-
-
Input variables5m 52s
-
(Locked)
Using input variables6m 23s
-
(Locked)
Output variables5m 50s
-
(Locked)
Sensitive data4m 10s
-
(Locked)
Looping with count7m 59s
-
(Locked)
Looping with for_each3m 26s
-
(Locked)
Expressions and functions6m 33s
-
(Locked)
Introduction to modules2m 38s
-
(Locked)
Using Terraform modules3m 55s
-
-
-
-