managing Existing AWS Infrastructure Using Terraform Import!
When working in real-world cloud environments, infrastructure is not always created using infrastructure as Code from day one.
Sometimes resources already exist - created manually through the AWS Console.
So the question becomes:
How do we bring those existing resources under Terraform management safely?
That’s exactly what this project demonstrates.
The Problem
You already have:
- A VPC
- A Security Group
- Possibly EC2 instances
But none of them are managed through Terraform.
Managing infrastructure manually:
- X Is not version controlled
- X Is not reproducible
- X Is error-prone
We need a structured way to manage it using Iac - without recreating everything.
The Solution: terraform import
Terraform provides a command that allows you to map existing cloud resources into Terraform state:
terraform import <resource_type.resource_name> <resource_id>
This command does not create infrastructure.
It simply tells Terraform:
| "This resource already exists. start managing it."
Architecture Overview
The workflow looks like this:
- Write Terraform configuration files (
.tf) - Configure AWS provider
- Reference existing VPC using a data source
- Define the Security Group in Terraform
- Use
terraform importto attach the real AWS resource to Terraform state - Validate using
terraform plan
Once imported, Terraform can now track and manage that resource.
Project Structure
terraform/
├── main.tf # Provider configuration
├── variables.tf # Region and VPC input
├── vpc.tf # Fetch existing VPC using data source
├── security_group.tf # Define Security Group to import
Import Workflow
- Initialize Terraform
terraform init
- Import Existing Security Group
terraform import aws_security_group.app_sg sg-xxxxxxxx
Terraform now maps the real AWS Security Group to the resource block.
Terraform validate
terraform plan
If everything matches, you’ll see No changes.
That means Terraform and AWS are in sync.
Conclusion
Adopting Infrastructure as Code doesn’t mean you need to rebuild everything from scratch.
With terraform import, you can gradually transition manual cloud infrastructure into a version-controlled, structured Terraform workflow.
This is a practical and realistic DevOps approach - especially in environments where infrastructure already exists.
Resources:
>> Connect With Me
If you enjoyed this post or want to follow my #30DaysOfAWSTerraformChallenge journey, feel free to connect with me here:
💼 LinkedIn: Amit Kushwaha
🐙 GitHub: Amit Kushwaha
📝 Hashnode / Amit Kushwaha
🐦 Twitter/X: Amit Kushwaha
Found this helpful? Drop a ❤️ and follow for more AWS and Terraform tutorials!

Top comments (0)