What resource meta-parameter can you use to enforce a specific dependency between resources?

Prepare for the HashiCorp Terraform Associate Exam. Utilize flashcards and multiple-choice questions with detailed hints and explanations. Boost your confidence and be ready for success!

Multiple Choice

What resource meta-parameter can you use to enforce a specific dependency between resources?

Explanation:
Explicit resource ordering in Terraform is controlled with depends_on. Terraform constructs an implicit dependency graph from references between resources, so attributes or outputs that reference another resource auto-create in the proper order. However, when there isn’t a direct reference showing a relationship, depends_on lets you force a specific creation sequence by listing the other resources that must be created first. For example, if an EC2 instance must be associated with a security group that must exist beforehand, you can add depends_on = [aws_security_group.sg] to the instance resource to ensure the security group is created first. Lifecycle, count, and for_each handle other aspects like resource behavior or how many instances to create, but they don’t enforce explicit creation order in the same way.

Explicit resource ordering in Terraform is controlled with depends_on. Terraform constructs an implicit dependency graph from references between resources, so attributes or outputs that reference another resource auto-create in the proper order. However, when there isn’t a direct reference showing a relationship, depends_on lets you force a specific creation sequence by listing the other resources that must be created first. For example, if an EC2 instance must be associated with a security group that must exist beforehand, you can add depends_on = [aws_security_group.sg] to the instance resource to ensure the security group is created first. Lifecycle, count, and for_each handle other aspects like resource behavior or how many instances to create, but they don’t enforce explicit creation order in the same way.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy