Curious Devs Corner

Curious Devs Corner

Share this post

Curious Devs Corner
Curious Devs Corner
Terraform Quickstart: Part 9 – Importing Existing Infrastructure
Mini-Courses

Terraform Quickstart: Part 9 – Importing Existing Infrastructure

How to Import Existing Cloud or GitHub Resources into Terraform Safely

KirshiYin's avatar
KirshiYin
Jun 26, 2025
∙ Paid

Share this post

Curious Devs Corner
Curious Devs Corner
Terraform Quickstart: Part 9 – Importing Existing Infrastructure
Share

Introduction

When you first started learning Terraform, you probably created everything from scratch—new resources, fresh environments, clean state. But real-world projects are rarely that simple.

Imagine your team inherits an existing GitHub organization or cloud project. The infrastructure is already there—S3 buckets, databases, repositories—created manually over months or years. Now, you need to bring that under Terraform control. You want to manage it using IaC without breaking anything. And you definitely don’t want to rewrite everything from scratch.

In this chapter, we’ll go deeper into the terraform import command. As promised earlier, you’ll learn how to bring existing infrastructure into Terraform so you can start managing it with version control.

📚Do you want to read all lessons in a single pdf? Check out my Terraform Quickstart ebook.

Import Overview

Workflow

  1. Terraform adds the resource to its state file (terraform.tfstate).

  2. The .tf files are NOT updated automatically.

    • You still need to manually write the Terraform configuration (main.tf) to match the imported resource.

    • Running terraform plan will show any differences.

Syntax

The command’s syntax is:

$ terraform import <resource_address> <resource_id>
  • resource_address: How the resource is defined in your Terraform config. Example: resource "aws_s3_bucket" "example"

  • resource_id: The actual identifier used by the provider (e.g., an S3 bucket name, GitHub repo name, or database ID).

Each provider has its own rules for what counts as a valid resource ID. Always check the official Terraform provider documentation before importing.

Hands-on Exercise: Importing an Existing GitHub Repository

Curious Devs Corner is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.

Keep reading with a 7-day free trial

Subscribe to Curious Devs Corner to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Kirshi Yin
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share