Courseiva
Understand Terraform's purposemediumMultiple ChoiceObjective-mapped

TF-004 Understand Terraform's purpose Practice Question

Exhibit

Refer to the exhibit.

```hcl
resource "aws_instance" "web" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"
}

resource "aws_s3_bucket" "data" {
  bucket = "my-data-bucket"
}
```

A team is reviewing the Terraform configuration shown in the exhibit. Which statement best describes the relationship between the two resources?

⚠ Common exam trap

HashiCorp often tests the misconception that Terraform creates resources in the order they appear in the configuration file, but the actual dependency mechanism is based on explicit references and `depends_on`, not lexical order.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

The two resources have no dependencies and can be created in any order.

Terraform resources are independent by default unless an explicit or implicit dependency is declared. In the exhibit, the S3 bucket and EC2 instance are defined without any `depends_on` argument or attribute reference (e.g., `aws_s3_bucket.example.arn` used in the EC2 instance configuration). Therefore, Terraform can create them in parallel or any order, as there is no directed acyclic graph (DAG) edge enforcing a creation sequence.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • The S3 bucket cannot be created until the EC2 instance is running.

    Why it's wrong here

    Terraform determines resource creation order based on explicit `depends_on` meta-arguments or implicit references between resource attributes. In this configuration, there is no explicit or implicit link from the S3 bucket resource to the EC2 instance's state or attributes. Therefore, the S3 bucket's creation is entirely independent of the EC2 instance's lifecycle, meaning it does not need the instance to be running or even created.

  • The S3 bucket depends on the EC2 instance because it is defined after it.

    Why it's wrong here

    Terraform constructs a dependency graph by analyzing all resource configurations for inter-resource references and explicit `depends_on` declarations, not by the order in which resources appear in the `.tf` file. The lexical order of resource blocks within a configuration file has no impact on the creation sequence or the establishment of dependencies. Terraform will always evaluate the entire configuration to determine the optimal parallel execution plan.

  • The two resources have no dependencies and can be created in any order.

    Why this is correct

    Terraform establishes dependencies either implicitly, when one resource's attribute is referenced by another, or explicitly, using the `depends_on` meta-argument. Given the absence of any such references or explicit declarations linking the EC2 instance and S3 bucket resources, Terraform correctly identifies them as entirely independent. This independence allows the Terraform graph to execute their creation in parallel or in any sequential order, as no ordering constraints exist.

  • The EC2 instance depends on the S3 bucket because the instance uses the bucket name.

    Why it's wrong here

    For an implicit dependency to be formed, the EC2 instance resource configuration would require a direct reference to an output attribute of the S3 bucket resource, such as `aws_s3_bucket.example.id` or `aws_s3_bucket.example.bucket`. Without any explicit attribute reference from the EC2 instance's definition to the S3 bucket, Terraform cannot establish a dependency. The EC2 instance is configured independently, without needing any information from the S3 bucket.

Quick reference

AWS S3 Storage Class Comparison

Storage ClassMin DurationRetrievalUse Case
S3 StandardNoneImmediateFrequently accessed data
S3 Standard-IA30 daysImmediateInfrequent access, rapid retrieval
S3 One Zone-IA30 daysImmediateNon-critical infrequent data
S3 Intelligent-TieringNoneImmediate–hoursUnknown or changing access patterns
S3 Glacier Instant90 daysMillisecondsArchive with instant retrieval
S3 Glacier Flexible90 daysMinutes–hoursArchive, flexible retrieval
S3 Glacier Deep Archive180 daysHoursLong-term compliance archive

About these practice questions

This TF-004 question is part of Courseiva's 428-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This TF-004 practice question is part of Courseiva's free HashiCorp certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the TF-004 exam.