Interview Prep/Real-World Interview/Write-Terraform tasks

Write the remote backend configuration with S3 and state locking.

BeginnerHands-onWrite-Terraform tasks
Answer
terraform {
  required_version = ">= 1.10"
  required_providers {
    aws = { source = "hashicorp/aws", version = "~> 5.0" }
  }
  backend "s3" {
    bucket       = "devopsshack-tfstate"
    key          = "network/prod/terraform.tfstate"
    region       = "ap-south-1"
    encrypt      = true
    use_lockfile = true
  }
}

Key trick → use_lockfile = true (Terraform 1.10+) uses S3's native conditional writes for locking, so a DynamoDB table is no longer needed (dynamodb_table is the older method and is deprecated). Backend blocks can't use variables.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-Terraform tasks