Complete the code to specify the backend type for storing Terraform state remotely.
terraform {
backend "[1]" {}
}The s3 backend stores the Terraform state file remotely in an AWS S3 bucket, which helps with performance and collaboration at scale.
Complete the code to enable state locking using DynamoDB to prevent concurrent state modifications.
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "state.tfstate"
region = "us-east-1"
dynamodb_table = "[1]"
}
}The dynamodb_table attribute specifies the DynamoDB table used for state locking. Naming it terraform-locks is a common practice.
Fix the error in the backend configuration to correctly enable encryption of the state file in S3.
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.
Fill both blanks to configure the S3 backend with versioning and a custom state file path.
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "[1]"
region = "us-east-1"
versioning = [2]
}
}The key defines the path to the state file, here set to env/prod/terraform.tfstate for environment separation. The versioning attribute enables S3 versioning with true to keep state history.
Fill all three blanks to configure remote state with S3 backend, enable locking, and specify the DynamoDB table.
terraform {
backend "s3" {
bucket = "[1]"
key = "[2]"
dynamodb_table = "[3]"
region = "us-west-2"
}
}The bucket is set to company-terraform-state as the S3 bucket name. The key specifies the path prod/terraform.tfstate for production environment state. The dynamodb_table terraform-locks enables state locking to prevent concurrent changes.