Terraform · Infrastructure as code
Why use remote state and how do you configure it?
Short answer
A remote backend stores state outside the runner so teams share one source of truth. Configure encryption, versioning and locking, and restrict access because state often contains sensitive values.
Local state works for a single developer on one machine. As soon as a team or CI system runs Terraform, state must live in a shared backend that supports locking and access control. The backend block is configured during terraform init and is not a normal resource.
terraform {
backend "s3" {
bucket = "acme-tfstate"
key = "prod/network/terraform.tfstate"
region = "us-east-1"
encrypt = true
use_lockfile = true
}
}Backend choices
- S3 with native lock files or a DynamoDB lock table
- Google Cloud Storage with object versioning
- Azure Storage with blob leasing
- HCP Terraform, which manages state and runs for you
Backend configuration is intentionally separate from variables and resources. Changing the bucket or key requires terraform init -migrate-state so Terraform can copy the existing state. Use one state per environment and per blast-radius boundary rather than one giant shared state.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What happens when you change the backend key?
- 2Why is backend configuration not a resource?
- 3How do you split state across teams?
- 4What are the trade-offs of HCP Terraform versus S3?
Say it in the interview
Remote state gives the team and CI one shared source of truth. I configure an S3 backend with encryption, versioning and locking, and I keep one state per environment and blast-radius boundary. Backend settings are initialized separately from resources, so moving state requires init with migrate-state. I never run CI against local state, because runners are ephemeral and concurrent jobs would race.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Terraform mock interview and get scored feedback on depth, clarity and confidence.