Member-only story
How to import an existing cloud infra using Terraform
Note: If you’re not a medium member, CLICK HERE
There are cases when you want to manage a cloud infrastructure (let’s take AWS for now) which is already created, and not in a phase where you can deploy everything from scratch.
In such scenarios, you’ve got two options:
- Write the configuration for the infra from scratch and then use
terraform planto manage the changes. - Use
terraform importto bring the existing resources into Terraform’s state file, and then manage the configuration. This is a much easier and safer way to start managing existing infra.
Here, I’ll focus on Option 2 → something I’ve already done in a client project to manage a large infra easily. This approach saved me a lot of time because I just wrote minimal config blocks instead of the entire configuration from scratch.
Example: Importing an Existing S3 Bucket
Let’s say you already have an S3 bucket in AWS that you want to start managing via Terraform.
Step 1: Write the Basic Configuration
From “basic”, I mean just laying the foundation with a minimal resource block in your Terraform codebase. Just keep the basic skeleton.

