The depends_on Meta-Argument
Use the depends_on
meta-argument to handle hidden resource or module dependencies that Terraform cannot automatically infer. You only need to explicitly specify a dependency when a resource or module relies on another resource's behavior but does not access any of that resource's data in its arguments.
Example
A good example of this is in an Application Security configuration exported with the cli-terraform (opens in a new tab).
The security
module (we'll soon talk about modules) acts as a container for all security-related configurations.
When you activate a security configuration, you want to ensure ALL security controls are properly configured first. In other words nothing in activate-security will proceed until the entire security module is complete
module "security" {
source = "./modules/security"
hostnames = var.hostnames
name = var.name
description = var.description
contract_id = var.contract_id
group_name = var.group_name
}
module "activate-security" {
source = "./modules/activate-security"
name = var.name
config_id = module.security.config_id
network = var.network
notification_emails = var.emails
note = var.activation_note
depends_on = [
module.security
]
}
Exercise
Update
Add 2 akamai_property_activation
resources to your property.tf. One for the staging network and the other one for the production network.
Hint: You can use the local.notes
defined in the Exercises section in module 7. Terraform Locals
Configure
Add a depends_on
to the production activation resource so that the production activation doesn't start until the staging activation has completed.
Plan/Apply
Run terraform plan
to confirm your changes. Run terraform apply
if all looks in order.
Commit
Commit your change and push it to GitHub.
Although this is not a real use case it shows how the order of the resources updates/creations can be somewhat controlled.