A Terraform configuration defines an aws_security_group and an aws_instance that references the security group. No explicit depends_on is set. How does Terraform determine the correct creation order?
- A. Terraform infers an implicit dependency from the reference
aws_security_group.example.idin the instance block, and creates the security group first✓ Correct - B. Terraform creates all resources in parallel by default; the engineer must add
depends_onto enforce ordering - C. Terraform always creates resources in the order they appear in the .tf files, top to bottom
- D. The engineer must use
terraform graphto manually specify the dependency before runningterraform apply
Explanation
When a resource attribute references another resource (e.g., security_groups = [aws_security_group.example.id]), Terraform automatically creates an implicit dependency. It builds a dependency graph and ensures the security group is created before the instance. Option C is wrong: Terraform does not use file order for sequencing; it uses the dependency graph. Option B is wrong: Terraform does create independent resources in parallel, but it correctly sequences resources that reference each other — depends_on is only needed for hidden dependencies that cannot be expressed through references. Option D is wrong: terraform graph is a read-only visualization tool; it does not configure dependencies.