DevOps Articles

Curated articles, resources, tips and trends from the DevOps World.

How to Use Terraform’s ‘for_each’, with Examples

3 years ago thenewstack.io
How to Use Terraform’s ‘for_each’, with Examples

Summary: This is a summary of an article originally published by The New Stack. Read the full original article here →

https://www.linkedin.com/in/tmcclung Terraform is one of the most popular https://en.wikipedia.org/wiki/Infrastructure_as_code (IaC) tools. With Terraform, you can write code that defines the infrastructure components you want and the configuration for them. You then execute that code, and Terraform will make sure that your infrastructure is set up the way you defined it.

In reality, Terraform code can be quite complicated.

21 resource "google_compute_instance""vm"{ for_each = { "vm1" = { vm_size = "e2-small", zone = "us-central1-a"} "vm2" = { vm_size = "e2-medium", zone = "us-central1-b"} "vm3" = { vm_size = "f1-micro", zone = "us-central1-c"} name = each.key machine_type = each.value.vm_size zone = each.value.zone

Made with pure grit © 2024 Jetpack Labs Inc. All rights reserved. www.jetpacklabs.com