Hands-On LabIntermediate

Import Existing Infrastructure into Terraform State Management

Use Terraform import blocks and the legacy import command to bring pre-existing Azure resources under Terraform state management.

55 minEstimated time
4Guided steps
AutoVerification
IsolatedSandbox
Import Existing Infrastructure into Terraform State Management

Lab overview

Organizations rarely start with a clean slate. Most cloud environments contain resources created manually through the portal, CLI scripts, or ARM templates long before an infrastructure-as-code strategy is adopted. Terraform's import capability bridges this gap by allowing engineers to bring existing resources under declarative state management without destroying and recreating them. Since Terraform 1.5, the declarative import block and terraform plan -generate-config-out workflow have made this process repeatable, auditable, and far less error-prone than the legacy imperative terraform import command.

In this lab, you will work with a set of pre-provisioned Azure resources (a virtual network, network security group, and storage account) that were created outside of Terraform. You will use the legacy terraform import command to understand the imperative approach, then progress to the modern declarative import block syntax with automatic configuration generation. By the end, all resources will be fully managed by Terraform with a clean terraform plan showing no changes.

Objectives

By completing this intermediate lab, you will be able to:

  • Use the legacy terraform import command to import an Azure resource into Terraform state
  • Write HCL configuration that matches the imported resource's actual state
  • Use declarative import blocks (Terraform 1.5+) to import multiple Azure resources
  • Generate Terraform configuration automatically with terraform plan -generate-config-out
  • Verify successful imports by running terraform plan and confirming zero changes
  • Identify Azure resource IDs using the Azure CLI for use in import operations

Who is this lab for?

This lab is designed for:

  • Cloud engineers adopting Terraform in environments with existing Azure infrastructure
  • DevOps practitioners who need to bring manually created resources under IaC management
  • Terraform Associate candidates preparing for exam objectives on importing existing infrastructure

Verified against your live environment

An automated validation engine inspects your actual resources and configurations as you work. Completion means the task was performed — not multiple choice, real-world proficiency.

[CHECK] validation_activelive
Inspecting deployed resources...
Verifying configuration state...
✓ Step requirements satisfied

More labs like this

Related reading

PremiumIncluded in Premium
Duration
55 min
Steps
4

Environment

Browser Code IDELive Cloud Environment

Every lab includes

  • Real environment, pre-credentialed
  • Automated checks on every step
  • Isolated sandbox, auto cleanup
  • AI-recommended next steps

Lab curriculum

  1. 01

    Logging into Azure CLI

  2. 02

    Discover Existing Azure Resources and Retrieve Resource IDs

    1 automated check

  3. 03

    Import a Resource Using the Legacy Terraform Import Command

    1 automated check

  4. 04

    Import Resources Using Declarative Import Blocks and Config Generation

    1 automated check

Skills validated

Azure StorageTerraformAzure Network Security GroupsAzure Virtual Network

Not the lab you were looking for?

Browse 150+ hands-on labs across AWS, Azure, Kubernetes, Docker, and cloud security.

Explore the catalog