TF-004 Implement and maintain state Practice Question
Exhibit
terraform {
backend "s3" {
bucket = "my-company-state-bucket"
key = "dev/terraform.tfstate"
region = "us-east-1"
encrypt = true
dynamodb_table = "tf-lock-table"
}
}Refer to the exhibit. A user has this backend configuration. The user then runs `terraform init` and receives an error: 'NoSuchBucket: The specified bucket does not exist'. What is the most likely cause?
⚠ Common exam trap
Many candidates assume Terraform will automatically create the S3 bucket when the backend is configured, but Terraform requires the bucket to exist beforehand. Understanding this prerequisite is key for the exam.
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 bucket does not exist and needs to be created.
The error 'NoSuchBucket: The specified bucket does not exist' directly indicates that the S3 bucket referenced in the backend configuration does not exist in the AWS account. Terraform requires the S3 bucket to already exist before running `terraform init` because it needs to store the state file; it does not create the bucket automatically. Therefore, the most likely cause is that the bucket has not been created yet.
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 bucket does not exist and needs to be created.
Why this is correct
The NoSuchBucket error explicitly indicates that the Amazon S3 bucket specified in the Terraform backend configuration does not exist within the AWS region where Terraform is attempting to initialize. Terraform's S3 backend requires a pre-existing S3 bucket to securely store the state file, which tracks the infrastructure managed by Terraform. Therefore, this error mandates that the user must manually create the S3 bucket with the exact name and in the correct region before terraform init can successfully configure the remote state.
- ✗
The AWS region is wrong.
Why it's wrong here
While a wrong AWS region could indirectly lead to a NoSuchBucket error if a bucket with that name exists in a different region, the error message itself directly signifies that the bucket does not exist in the region Terraform is currently targeting. AWS S3 bucket names are globally unique but buckets themselves are regional resources. If Terraform is configured for us-east-1 and the bucket only exists in eu-west-1, the us-east-1 endpoint will report NoSuchBucket because it cannot find the resource locally.
- ✗
The DynamoDB table is missing.
Why it's wrong here
A missing DynamoDB table, which is typically used for state locking with the S3 backend, would result in a different error message. Terraform would encounter an AccessDeniedException or ResourceNotFoundException from the DynamoDB service when attempting to acquire a lock, or a specific "lock error" message, not a NoSuchBucket error. The NoSuchBucket error is exclusively an S3 service response, indicating the absence of the specified S3 resource itself.
- ✗
The credentials lack S3 permissions.
Why it's wrong here
If the AWS credentials used by Terraform lacked the necessary S3 permissions to interact with the specified bucket, the AWS API would return an AccessDenied error. This error explicitly signifies an authorization failure, meaning the authenticated principal is not permitted to perform the requested action on the resource. In contrast, a NoSuchBucket error indicates that the resource itself simply does not exist, irrespective of the caller's permissions.
Quick reference
AWS S3 Storage Class Comparison
| Storage Class | Min Duration | Retrieval | Use Case |
|---|---|---|---|
| S3 Standard | None | Immediate | Frequently accessed data |
| S3 Standard-IA | 30 days | Immediate | Infrequent access, rapid retrieval |
| S3 One Zone-IA | 30 days | Immediate | Non-critical infrequent data |
| S3 Intelligent-Tiering | None | Immediate–hours | Unknown or changing access patterns |
| S3 Glacier Instant | 90 days | Milliseconds | Archive with instant retrieval |
| S3 Glacier Flexible | 90 days | Minutes–hours | Archive, flexible retrieval |
| S3 Glacier Deep Archive | 180 days | Hours | Long-term compliance archive |
Go deeper
Related to this question
About these practice questions
Courseiva writes every TF-004 question from scratch — 428 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
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.