Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 02-git/01-git-fork-vs-git clone.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Here’s how you’d typically use both:

> So: **Fork = GitHub-level action**, **Clone = Local machine-level action**.


<!-- Addedd few lines to to test pull request to main branch -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Architectural Decision: Why We Store Terraform State in AWS S3 vs. Git

This document explains our decision to use AWS S3 and DynamoDB for Terraform state management instead of storing state files directly in version control.

## 1. Security Risks (Plain-Text Secrets)
* **The Problem:** Terraform state files store infrastructure details in plain text. This includes database passwords, private keys, API tokens, and initial administrative credentials.
* **The Git Flaw:** Committing a state file to Git injects sensitive credentials into version control history. Even if the file is deleted later or the repository is private, secrets remain permanently baked into the Git history.

## 2. Concurrency Issues (No State Locking)
* **The Problem:** Simultaneous deployments by multiple engineers can overwrite changes, leading to corrupted state files or destroyed cloud resources.
* **The Git Flaw:** Git lacks a live state locking mechanism. AWS S3 combined with DynamoDB natively locks the state file during execution. Git only detects conflicts during a `git push`, which happens after infrastructure changes are already applied.

## 3. Automation Bottlenecks (Race Conditions)
* **The Problem:** Terraform requires real-time state accuracy before modifying infrastructure.
* **The Git Flaw:** Git introduces race conditions. Engineers must manually commit and push updated state files. If someone forgets to push or pull the latest changes, deployments run on stale data and break the infrastructure.

---

## Interview Cheat Sheet: Summary Answer

If asked, **"Have you considered storing the state file in Git instead of AWS S3?"**, answer with:

> "We explicitly avoid storing the state file in Git because it violates security and operational best practices. First, state files contain plain-text secrets that should never be committed to version control. Second, Git doesn't support native state locking, which creates a massive risk of race conditions and state corruption if two team members run deployments simultaneously. We use AWS S3 with DynamoDB precisely because it gives us automated encryption at rest, automatic version history, and real-time state locking to ensure team safety."