Course contentsShow
← Cloud and Infrastructure
Lesson 706 of 2,98913. Infrastructure as Code FoundationsFree lesson

Import Existing Resources

Learn how to bring existing manually-created infrastructure under IaC management.

Import Existing Resources

What you'll learn: How to bring manually-created cloud infrastructure into your IaC management system without destroying and recreating it.

The Problem

You've been learning how Infrastructure as Code tracks resources through a state file. But what happens when you already have infrastructure running in your cloud account that was created manually through the console or CLI? You can't just write IaC configuration and apply it—that would try to create those resources again, causing conflicts or errors.

The Import Solution

Importing is the process of telling your IaC tool about resources that already exist, so it can add them to its state file and manage them going forward. Think of it like adopting a stray cat: the cat already exists, you're just bringing it into your household and making it officially yours.

When you import:

  1. You write the configuration describing the existing resource
  2. You run an import command with the resource's real cloud ID (like an EC2 instance ID)
  3. The IaC tool fetches the current configuration from your cloud provider
  4. It adds that resource to the state file
  5. Now your IaC tool "owns" that resource and can manage future changes

Why This Matters

Without import, you'd have two bad options: either ignore existing resources (letting them drift from IaC management) or destroy and recreate them (causing downtime). Import lets you gradually adopt IaC for brownfield environments without disruption.

After import, you can use state refresh and drift detection to ensure your configuration matches reality, then manage that resource just like any other IaC-managed infrastructure.

Key Takeaway: Importing brings existing cloud resources under IaC management by adding them to the state file, enabling you to manage legacy infrastructure without recreating it.