Fix Terraform Error: CloudWatch Log Group Already Exists
Fix terraform CloudWatch Log Group ResourceAlreadyExistsException. Import orphaned log groups, prevent Lambda auto-creation
DevOps
How to fix 'Backend configuration changed' and safely migrate Terraform state between backends (local to S3, S3 to Terraform Cloud).
Error: Backend configuration changedTerraform detected that your backend configuration has changed since the last terraform init. This happens when migrating from local to remote state, changing S3 buckets, or switching to Terraform Cloud.
# Terraform will ask if you want to migrate state
terraform init -migrate-state
# Answer 'yes' to copy state to new backend# If you want to start fresh (WARNING: loses state!)
terraform init -reconfigure# Step 1: Pull current state
terraform state pull > terraform.tfstate.backup
# Step 2: Update backend config in .tf files
# Step 3: Initialize new backend
terraform init -reconfigure
# Step 4: Push state to new backend
terraform state push terraform.tfstate.backup# Before (local backend — default)
# No backend block
# After
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "prod/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-locks"
encrypt = true
}
}terraform init -migrate-state
# Type 'yes' when promptedterraform plan — always review before applyingterraform validate — catches syntax errors earlyLearn to avoid these errors with interactive, project-based courses:
This error is common and fixable. Follow the solutions above, and check our Terraform course for hands-on training that covers real-world troubleshooting scenarios.
Fix terraform CloudWatch Log Group ResourceAlreadyExistsException. Import orphaned log groups, prevent Lambda auto-creation
Fix terraform import errors when a resource already exists in state. Covers state rm, state show, reimport workflow, import blocks
Fix terraform too many command line arguments errors. Correct -var syntax, quote values with spaces, and learn proper Terraform CLI argument format for plan
Fix terraform invalid escape sequence errors. Double backslashes for Windows paths, use heredocs for regex, and learn all valid HCL escape sequences.