Skip to content

Latest commit

 

History

History
15 lines (13 loc) · 1.3 KB

06-terraform-s3-as-backend.md

File metadata and controls

15 lines (13 loc) · 1.3 KB

S3 Bucket for Remote backend

Problem with Local Statefile

By default, Terraform stores its statefile (terraform.tfstate) locally on the machine where Terraform is executed. This approach has several issues:

  1. Risk of Data Loss: If the local machine crashes or the file is accidentally deleted, the statefile is lost.
  2. Collaboration Challenges: When multiple users work on the same Terraform project, local statefiles can lead to inconsistencies and conflicts.
  3. Concurrency Issues: If two users apply changes simultaneously, the statefile may become corrupted.
  4. Security Risks: Local statefiles may contain sensitive data (e.g., resource IDs, credentials) that could be exposed.

How S3 Bucket Solves These Problems

  1. Centralized Storage: The statefile is stored in a remote S3 bucket, making it accessible to all team members.
  2. Versioning Support: S3 enables versioning, allowing rollback to previous state versions if needed.
  3. State Consistency: When used with DynamoDB for state locking, S3 prevents simultaneous modifications, avoiding corruption.
  4. Security & Backup: S3 supports encryption and automated backups, reducing security risks and ensuring recovery options.
  5. Scalability: S3 can handle large statefiles efficiently without performance issues.