TF-Associate-004 - Terraform configuration (21% of the exam) - 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.

Exam traps in Terraform configuration

Answers that look right on this material and are not. Each one is a distractor from a different question in the TF-Associate-004 bank for this domain.

  • An implicit dependency applies only to data sources, whereas an explicit dependency applies only to managed resources

    Why it is wrong: Tempting because data sources also participate in ordering, but both dependency kinds apply to managed resources and data sources alike, so this restriction is false.

  • By reading the top-to-bottom order in which the resource blocks appear within the configuration file

    Why it is wrong: Tempting because file order looks like execution order, but Terraform ignores block position and derives ordering from references, so this is wrong.

  • To copy attribute values from one resource into another during the apply phase

    Why it is wrong: Value passing is done through attribute references, not depends_on, which conveys ordering only and moves no data, so this is incorrect.

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.