TF-Associate-004 - Terraform configuration - Section 4f

Define resource dependencies in configuration.

Most dependencies are implicit from references; depends_on declares a dependency Terraform cannot infer. Candidates should know when depends_on is required (a hidden ordering the configuration does not express) and why over-using it harms parallelism.

implicit dependencydepends_onexplicit dependencydependency graph ordering

Practice question for this objective

Free sampleTerraform configurationmedium

An application instance reads configuration files that a provisioning script writes into an S3 bucket, but nothing in the aws_instance block references the aws_s3_bucket. The practitioner needs Terraform to always create the bucket before the instance, even though no attribute links them. Which change expresses this requirement correctly?

resource "aws_s3_bucket" "config" {
  bucket = "app-config-store"
}
resource "aws_instance" "app" {
  ami           = var.ami_id
  instance_type = "t3.small"
}
  • AAdd depends_on = aws_s3_bucket.config to the aws_instance.app block, passing the bucket as a single reference.
  • BAdd depends_on = [aws_s3_bucket.config] to the aws_instance.app block to declare an explicit dependency. Correct
  • CAdd a lifecycle block with create_before_destroy = true to the aws_s3_bucket.config so it is provisioned earlier.
  • DInterpolate aws_s3_bucket.config.bucket into a tag on the instance so an implicit dependency forms automatically.
Use depends_on with a bracketed list to declare an ordering Terraform cannot infer from resource attribute references. When a dependency exists only at runtime and is not visible in any expression, Terraform cannot infer it. depends_on accepts a list of resource references and adds the graph edge so the bucket is created before the instance.

Why A is wrong: The intent is right but the syntax is wrong; depends_on takes a list of references in square brackets, so an unbracketed single reference is invalid.

Why B is correct: depends_on states an ordering that Terraform cannot infer from expressions, forcing the bucket to be created before the instance for this hidden runtime relationship.

Why C is wrong: create_before_destroy governs replacement ordering of a single resource, not the relative creation order of two separate resources, so it does not express this dependency.

Why D is wrong: This would work technically by creating a reference, but it forces an artificial attribute link that misrepresents the design when depends_on is the intended tool for hidden dependencies.

See more TF-Associate-004 practice questions, answers explained.

More in this domain

Back to all Terraform configuration objectives, or the TF-Associate-004 cert hub.

Examworthy is not affiliated with or endorsed by HashiCorp. Original, blueprint-aligned practice material only.