Preparing Practice Exam…
Please wait a moment while the system generates the exam questions, answers, and study session.
Please wait a moment while the system generates the exam questions, answers, and study session.
HashiCorp Certified: Terraform Associate (003) · HashiCorp
Hotspot Scenario
Select the appropriate option to complete the statement. Click Check Answer below to see the marked solution.
Hotspot Solution:
depends_on In Terraform, sometimes the order in which resources are created, updated, or destroyed is important because some resources might rely on others. For example, you might not want a virtual machine to be created before the network it relies on is set up. However, there are situations where Terraform cannot infer dependencies from the configuration alone, especially when the dependency is indirect or based on operational considerations outside of Terraform's knowledge. The depends_on meta-parameter is used for this purpose. You can add depends_on to any resource block to explicitly specify that the resource depends on other resources. Terraform will ensure that the resources listed in depends_on are created before the resource that defines the dependency.
Written by other learners. Comments can disagree with the marked answer — check the official documentation when in doubt.
In the above example, even though the aws_instance.app_server doesn't directly reference the aws_cloudwatch_log_group.example, we've used depends_on to tell Terraform that the app_server should only be created after the example-log-group CloudWatch Log Group is created. This ensures that your logging infrastructure is in place before your application starts running. depends_on is particularly useful in cases where Terraform cannot automatically determine the correct order for creating, updating, or destroying resources based on the configuration alone.
depends_on In Terraform, sometimes the order in which resources are created, updated, or destroyed is important because some resources might rely on others. For example, you might not want a virtual machine to be created before the network it relies on is set up. However, there are situations where Terraform cannot infer dependencies from the configuration alone, especially when the dependency is indirect or based on operational considerations outside of Terraform's knowledge. The depends_on meta-parameter is used for this purpose. You can add depends_on to any resource block to explicitly specify that the resource depends on other resources. Terraform will ensure that the resources listed in depends_on are created before the resource that defines the dependency.
Suppose you have a scenario where you need to ensure a logging service is up and running before your main application starts, but there's no direct reference between the two in your Terraform configuration. You could use depends_on to define this relationship: resource "aws_cloudwatch_log_group" "example" { name = "example-log-group" # Other configuration... } resource "aws_instance" "app_server" { ami = "ami-123456" instance_type = "t2.micro" # Other configuration... # Manually specify dependency on the CloudWatch Log Group depends_on = [aws_cloudwatch_log_group.example] }