From the course: Hashicorp Certified Terraform Associate (003) Cert Prep

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Looping and creating multiple instances

Looping and creating multiple instances

- [Instructor] Resource dependencies in Terraform. So in Terraform, dependencies refers to the relationship between resources in a configuration. Terraform uses this information to determine the correct order in which to create or modify your resources. So here, I have the configuration, just walk to you through how the depends_on works. Okay, so I have resource block here for aws_security_group for creating EC2 instance. Whenever you see me use dot, dot, dot here, which I have actually commented out is just to show that that other parameters that should come with it. I just want to manage the space. So this is for creating AWS security group. This is for EC2 instance. And here, I am explicitly specifying the dependency on the security group. I just want to tell Terraform that AWS EC2 instance here depends on the existence of my resource group, okay? So I want Terraform to provision the resource group first before EC2 instance. So this is a way to let Terraform note that it shouldn't…

Contents