Description
Immutable infra: blue-green deploy, rollback strategy, artifact management, drift detection policy.

Mutable infrastructure is the root cause of configuration drift—every emergency SSH fix creates a server that cannot be reproduced. Immutable infrastructure treats servers as disposable: you never patch a running server, you replace it with a new one built from the same artifacts. STEP 1 — CORE PRINCIPLE Every deployment creates a complete new environment from version-controlled artifacts. The old environment is destroyed (or kept as rollback target). No package updates on running instances. No manual config changes. The artifact is the source of truth, not the server state. STEP 2 — BLUE-GREEN DEPLOYMENT - BLUE: current production environment (live traffic) - GREEN: new environment (built from latest artifacts) - Steps: 1. Build green environment in parallel with blue (same resources, isolated) 2. Run smoke tests against green (health checks, critical-path assertions) 3. Switch load balancer/router to green (instantaneous cutover or gradual via weighted DNS) 4. Monitor green for N minutes (N=10 for simple apps, N=60 for complex) 5. Destroy blue environment (or keep as rollback target) STEP 3 — ROLLBACK STRATEGY - Immediate: Switch load balancer back to blue. Environment untouched, instant rollback. If blue was destroyed, rebuild from the same AMI/container tag. - Staged: Rebuild previous environment from version-controlled artifacts. Slower but guaranteed identical. - Roll-forward: Fix forward on green. Only when the fix is faster than rolling back. STEP 4 — ARTIFACT MANAGEMENT - Immutable artifact ID (AMI ID, container digest, tarball SHA256) recorded in deployment metadata. - Artifacts tagged with git commit SHA, build number, environment, timestamp. - Retention: keep last 10 successful artifacts for instant rollback. Archive older artifacts to S3/Blob storage with 90-day lifecycle. STEP 5 — TERRAFORM/CLOUDFORMATION LIFECYCLE ```hcl resource "aws_instance" "app" { ami = var.app_ami_id # never change in-place instance_type = "t3.medium" user_data = filebase64("${path.module}/user_data.sh") lifecycle { create_before_destroy = true # blue-green for ASG } } ``` Key practice: never use `user_data` to install packages at boot. Bake everything into the AMI. user_data should only configure runtime parameters (environment name, log destinations). STEP 6 — DRIFT DETECTION - Periodic compliance scan: compare running instance metadata against the desired state in the artifact registry. Flag any differences. - Emergency access procedure: if SSH is needed, use a bastion host with session recording. After fixing, create a new artifact version. Never patch directly. OUTPUT: Blue-green deployment plan, rollback decision tree, artifact tag schema, Terraform lifecycle config, drift detection policy.

Comments (0)

No comments yet. Be the first!

Rating

0 Rating

Log in to rate

Statistics

Rating 0.0 (0)
Bookmarked 0
Comments 0
The prompt has been copied to the clipboard.