Prompt
How do I migrate from manual AWS console changes to Terraform?
Latest observation
A good way to migrate from “clickops” in the AWS console to Terraform is to do it in stages so you don’t accidentally recreate or destroy resources.
Recommended approach
1) Inventory what already exists
List the AWS resources that are currently managed manually:
- VPCs, subnets, security groups
- EC2, ALB, RDS, S3, IAM, etc.
- Tagging and naming conventions
- Dependencies between resources
It helps to draw a simple dependency map first.
2) Decide what Terraform will manage
Not everything has to move at once. Start with:
- low-risk resources
- stable infrastructure
- things that change infrequently
Leave out highly dynamic or one-off resources until later.
3) Create Terraform code that matches the existing infrastructure
Write .tf files that describe the current setup as closely as possible.
A common mistake is to “improve” the config while importing. Don’t do that initially—your goal is to match reality first.
Example:
resource "aws_s3_bucket" "logs" {
bucket = "my-company-logs"
}
4) Import existing resources into Terraform state
Use terraform import to attach real AWS resources to Terraform state.
Example:
terraform import aws_s3_bucket.logs my-company-logs
For many resources, the import ID is not just the name; check the provider docs.
Typical flow:
- write resource block
- run
terraform import - run
terraform plan - adjust config until plan is clean
5) Repeat until terraform plan shows no unintended changes
After import, Terraform may still want to change things because:
- your code doesn’t match the existing resource exactly
- default values differ
- AWS provider expects arguments you haven’t specified
- some attributes are computed or ignored
Keep iterating until:
terraform plan
shows only the changes you actually want.
6) Move to remote state and locking
If you aren’t already, use remote state so the team can collaborate safely.
Common setup:
- S3 backend for state
- DynamoDB for state locking
Example backend:
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "prod/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-locks"
encrypt = true
}
}
7) Standardize naming and tagging
Once resources are under Terraform control, normalize:
- tags
- naming
- variable structure
- module layout
Do this after import, not before, unless you’re ready to make real infrastructure changes.
8) Use modules for repeatable patterns
When you have multiple similar resources, refactor into modules:
- networking
- ECS/EKS
- app tiers
- security groups
- IAM roles
This makes future changes safer and more consistent.
9) Protect critical resources during transition
Use safeguards while migrating:
lifecycle { prevent_destroy = true }for critical resources-targetonly for temporary migration steps, not as a long-term habit- backups/snapshots before major changes
- change windows for production systems
10) Remove manual changes from the process
Once Terraform owns a resource:
- stop editing it in the AWS console
- make all future changes through Terraform
- use CI/CD to run
terraform planandterraform apply
Otherwise, you’ll get drift.
Practical migration pattern
For each resource:
- Create Terraform resource block
- Import existing AWS resource
- Run
terraform plan - Fix mismatches
- Apply only after plan is clean
- Document ownership and dependencies
Tools that can help
- Terraformer: can generate Terraform config/state from existing AWS resources
- terraform import: best for controlled migration
- AWS Config / CloudTrail: useful for understanding what exists and what changed
Terraformer can speed up discovery, but generated code usually needs cleanup.
Common pitfalls
- Importing without matching config first
- Forgetting dependencies, causing replacement
- Editing resources manually after import
- Not using remote state
- Migrating everything at once
- Assuming provider defaults match AWS defaults
Suggested migration strategy
If this is a production environment:
- start with non-critical resources
- import and stabilize networking
- migrate security groups and IAM
- then app resources
- finally data stores and sensitive components
If you want, I can also give you:
- a step-by-step migration checklist, or
- a real AWS example like importing an S3 bucket, security group, or EC2 instance.