Skip to main content
This guide explains how to bring existing infrastructure under Terraform management using the terraform import command. It covers the required arguments, Azure-specific ID formats, example usage, a recommended import workflow, and best practices to avoid surprises after importing resources.

What terraform import does (and does not do)

  • terraform import connects an existing real resource to a declared resource block in your Terraform state.
  • It does not generate HCL configuration, nor does it create, modify, or destroy the remote resource.
  • After a successful import, the resource’s attributes are recorded in the Terraform state and Terraform will manage it going forward.

Required arguments

The import command expects two positional arguments:
  1. ADDR — the resource address in your Terraform configuration (must already exist in your .tf files). Example: azurerm_storage_account.example.
  2. ID — the provider-specific identifier of the real resource (format depends on provider).
Example syntax:

ADDR vs ID — quick comparison

For Azure resources the ID is typically the full Azure Resource Manager (ARM) ID shown above.

Example: import an Azure Storage Account

Run the import using the HCL resource address and the ARM resource ID:

Trimmed help text (reference)

  1. Ensure the Terraform configuration contains a resource block that matches the resource type you intend to import. terraform import does not create this block for you.
  2. Confirm the correct provider-specific ID format from provider docs (for Azure, use the ARM resource ID).
  3. Run terraform import ADDR ID.
  4. Immediately run terraform plan to detect any differences (drift) between the imported state and your HCL.
  5. Reconcile your HCL: update default values, add missing attributes, or change values to reflect the desired configuration.
  6. Run terraform plan again until the plan shows only intended changes, then terraform apply to persist any HCL-driven changes (if required).
Note: terraform import is especially useful when adopting Terraform in a brownfield environment, recovering a lost state file, or migrating manually created resources into infrastructure-as-code without causing downtime or recreation.

Best practices and important clarifications

  • The resource block must exist in the configuration before importing. Terraform will not generate HCL for you.
  • After import, the imported resource’s state attributes may differ from the configuration; always run terraform plan and reconcile differences.
  • Import only affects the state file; it does not change configuration files or the remote resource.
  • Use provider documentation to determine the correct ID format for imports. For Azure, this is usually the ARM resource ID.
  • Consider using separate branches and state backups when importing multiple resources to reduce risk.

Tools and further resources

Note: After importing, reconcile your configuration with the imported state and run terraform plan and terraform apply only when you have verified the intended changes.
This completes the coverage of terraform import. It is the primary CLI command for bringing existing resources into Terraform state when adopting infrastructure-as-code in environments that already have resources provisioned.

Watch Video

Practice Lab