Complete the code to specify the backend type for Terraform state storage.
terraform {
backend "[1]" {}
}The s3 backend stores Terraform state in an Amazon S3 bucket, which is commonly used for disaster recovery.
Complete the code to enable versioning on the S3 bucket for state recovery.
resource "aws_s3_bucket" "terraform_state" { bucket = "my-terraform-state" versioning { status = "[1]" } }
Enabling versioning on the S3 bucket allows you to recover previous versions of the Terraform state file in case of accidental deletion or corruption.
Fix the error in the backend configuration to enable encryption of the state file.
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "state.tfstate"
region = "us-east-1"
encrypt = [1]
}
}The encrypt attribute expects a boolean value true without quotes to enable encryption of the state file in S3.
Fill both blanks to configure DynamoDB for state locking and specify the bucket name.
terraform {
backend "s3" {
bucket = "[1]"
key = "terraform.tfstate"
region = "us-west-2"
dynamodb_table = "[2]"
encrypt = true
}
}The bucket should be the S3 bucket name where the state is stored, and dynamodb_table is the DynamoDB table used for state locking to prevent concurrent modifications.
Fill all three blanks to create an S3 bucket with versioning and a DynamoDB table for locking.
resource "aws_s3_bucket" "terraform_state" { bucket = "[1]" versioning { status = "[2]" } } resource "aws_dynamodb_table" "terraform_lock" { name = "[3]" billing_mode = "PAY_PER_REQUEST" hash_key = "LockID" attribute { name = "LockID" type = "S" } }
This configuration creates an S3 bucket named my-terraform-state with versioning enabled, and a DynamoDB table named terraform-lock-table for state locking.