Implicit Resource Dependencies
Explore how Terraform automatically manages implicit resource dependencies by creating dependency graphs within modules. Understand the use of the -target flag to plan and destroy specific resources, and learn how Terraform ensures proper order of operations regardless of declaration order.
We'll cover the following...
Dependencies
The dependencies are the bane of any infrastructure manager’s life. If we switch off the Virtual Machine (VM), who will complain? What about the load balancer?
Stories of switching off servers to see who complains as a way of managing unknown dependencies are incredibly common in the IT industry.
Terraform can help manage that problem by codifying and tracking resource dependencies. However, it’s important to remember that it does not do so by magic and that our application dependencies may still need to be mapped out by whoever’s in charge of them.
Implicit dependency
Initially, we need to set up our credentials. Then, we create a new directory with a Terraform module.
We also create a Terraform module with a defined AWS provider.
Then we add two resources to the dependencies.tf file. The first is an AWS VPC, similar to the one we created before. This time, we give it a name directly in the Terraform module, ltthw-vpc, rather than doing so manually in the AWS console.
The second resource type is aws_subnet ...