Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Enable and Configure S3 Versioning
📖 Scenario: You are managing a cloud storage bucket for a small company. To protect against accidental file deletions or overwrites, you want to enable versioning on the bucket. This way, every change to a file is saved as a new version, allowing recovery if needed.
🎯 Goal: Create an AWS S3 bucket with versioning enabled using infrastructure as code. You will first define the bucket, then add a versioning configuration, and finally complete the setup to ensure versioning is active.
📋 What You'll Learn
Create an S3 bucket named exactly my-versioned-bucket
Add a versioning configuration block with status set to Enabled
Ensure the final configuration is valid and deployable
💡 Why This Matters
🌍 Real World
Versioning in S3 helps protect important files from accidental deletion or overwrites by keeping multiple versions of each object.
💼 Career
Cloud engineers and DevOps professionals often configure S3 versioning to ensure data durability and recovery options in production environments.
Progress0 / 4 steps
1
Create the S3 bucket resource
Write the Terraform code to create an AWS S3 bucket resource named my-versioned-bucket using the resource name aws_s3_bucket.my_versioned_bucket.
AWS
Hint
Use the resource block with type aws_s3_bucket and name my_versioned_bucket. Set the bucket attribute to "my-versioned-bucket".
2
Add versioning configuration block
Add a versioning block inside the aws_s3_bucket.my_versioned_bucket resource. Set the enabled attribute to true to enable versioning.
AWS
Hint
Inside the bucket resource, add a versioning block with enabled = true to turn on versioning.
Add the mfa_delete attribute inside the versioning block and set it to false. This disables MFA delete for simplicity in this project.
AWS
Hint
Inside the versioning block, add mfa_delete = false to explicitly disable MFA delete.
4
Complete the S3 bucket versioning configuration
Ensure the full Terraform resource aws_s3_bucket.my_versioned_bucket includes the bucket name my-versioned-bucket and the versioning block with enabled = true and mfa_delete = false.
AWS
Hint
Review the entire resource block to confirm all required attributes are present and correctly set.
Practice
(1/5)
1. What is the main purpose of enabling S3 versioning on a bucket?
easy
A. To keep multiple copies of files automatically for recovery and tracking
B. To increase the storage capacity of the bucket
C. To encrypt files stored in the bucket
D. To restrict access to the bucket
Solution
Step 1: Understand what S3 versioning does
S3 versioning keeps multiple versions of the same file automatically.
Step 2: Identify the main benefit
This helps recover from mistakes and track changes over time.
Final Answer:
To keep multiple copies of files automatically for recovery and tracking -> Option A
Quick Check:
S3 versioning = multiple copies for recovery [OK]
Hint: Versioning means saving file copies automatically [OK]
Common Mistakes:
Thinking versioning increases storage size limit
Confusing versioning with encryption
Assuming versioning controls access permissions
2. Which of the following is the correct way to enable versioning in an AWS S3 bucket configuration?
easy
A. versioning = true
B. versioning { enabled = true }
C. enable_versioning = yes
D. versioning: active
Solution
Step 1: Recall the syntax for enabling versioning
Versioning is enabled by setting a block with enabled = true.
Step 2: Match the correct syntax
Only versioning { enabled = true } matches the correct structure.
Final Answer:
versioning { enabled = true } -> Option B
Quick Check:
Enable versioning with block and enabled=true [OK]
Hint: Look for block with enabled = true syntax [OK]
Common Mistakes:
Using assignment without block braces
Using yes/no instead of true/false
Using colon instead of equals sign
3. Given the following Terraform snippet for an S3 bucket, what will be the versioning state of the bucket after deployment?
A. enabled must be a string "true", not boolean true
B. Versioning cannot be enabled during bucket creation
C. Bucket name must be unique globally
D. versioning should be a block, not an assignment; remove '='
Solution
Step 1: Identify syntax error in versioning block
The code uses versioning = { ... } which is incorrect syntax for a block.
Step 2: Correct syntax for versioning block
Versioning must be declared as a block without '=' like versioning { enabled = true }.
Final Answer:
versioning should be a block, not an assignment; remove '=' -> Option D
Quick Check:
Blocks use braces without '=' [OK]
Hint: Blocks use braces without '=' sign [OK]
Common Mistakes:
Using '=' with blocks
Using string instead of boolean for enabled
Ignoring bucket name uniqueness errors
5. You want to protect important files in your S3 bucket from accidental deletion but still allow updates. How does enabling versioning help achieve this, and what additional step should you take for stronger protection?
hard
A. Versioning keeps old file copies; enable MFA delete to require extra confirmation for deletions
B. Versioning encrypts files; enable bucket policies to restrict access
C. Versioning compresses files; enable lifecycle rules to archive old versions
D. Versioning increases storage; enable logging to track deletions
Solution
Step 1: Understand versioning's role in protection
Versioning keeps all versions of files, so deleted files can be recovered.
Step 2: Identify additional protection for deletions
Enabling MFA delete adds a requirement for multi-factor authentication to delete versions, preventing accidental or unauthorized deletions.
Final Answer:
Versioning keeps old file copies; enable MFA delete to require extra confirmation for deletions -> Option A