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.

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 importcommand to import an Azure resource into Terraform state - Write HCL configuration that matches the imported resource's actual state
- Use declarative
importblocks (Terraform 1.5+) to import multiple Azure resources - Generate Terraform configuration automatically with
terraform plan -generate-config-out - Verify successful imports by running
terraform planand 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.
More labs like this
Challenge - Import and Refactor Existing Infrastructure with Terraform
Bring pre-existing Azure resources under Terraform management without recreating them, reconcile your configuration to a zero-change plan, then refactor the storage account into a reusable module.
Configure Terraform Remote State with Azure Storage Backend
Migrate Terraform state from local to Azure Storage, configure the azurerm backend with partial configuration, and observe state locking via blob leases.
Deploy a Full Azure Environment Using Bicep Infrastructure as Code
Write modular Bicep templates to deploy a VNet, App Service, SQL Database, and Key Vault, then deploy the full environment using Azure CLI.
Related reading
Environment
Every lab includes
- Real environment, pre-credentialed
- Automated checks on every step
- Isolated sandbox, auto cleanup
- AI-recommended next steps
Lab curriculum
- 01
Logging into Azure CLI
- 02
Discover Existing Azure Resources and Retrieve Resource IDs
1 automated check
- 03
Import a Resource Using the Legacy Terraform Import Command
1 automated check
- 04
Import Resources Using Declarative Import Blocks and Config Generation
1 automated check
Skills validated
Not the lab you were looking for?
Browse 150+ hands-on labs across AWS, Azure, Kubernetes, Docker, and cloud security.