Import existing resources overview
This topic provides an overview of the Terraform CLI commands and configuration language constructs that let you import existing infrastructure resources so that you can manage them with Terraform.
Hands-on: Try the Import Terraform Configuration tutorial.
Workflows
Terraform supports several approaches to importing existing resources, depending on how many resources you need to import and whether you want to discover them first.
Import a single resource
Use the terraform import command to import a single existing resource into Terraform state. Before running the command, you must manually write a resource configuration block that describes where Terraform should map the imported object. The command runs locally and does not have access to HCP Terraform workspace variables. Refer to Import existing resources for more information.
Import multiple resources
Use the import block in your Terraform configuration to import more than one resource at a time. The import block generates configuration and lets you review imports as part of your normal plan and apply workflow. Refer to the import block reference in the Terraform configuration language documentation for more information.
Discover and import unmanaged resources
Use the terraform query command to search existing infrastructure for resources that are not yet managed by Terraform. The terraform query command discovers resources without requiring you to know the resource address in advance. When you run queries remotely in HCP Terraform or Terraform Enterprise, you can also evaluate policies against configuration generated from the discovered resources. Refer to Evaluate policies during search for more information.
Resource importability
Each resource in Terraform must implement some basic logic to become importable. As a result, you cannot import all Terraform resources.
The resources that you can import are documented at the bottom of each resource documentation page in the Terraform Registry. If you have issues importing a resource, report an issue in the relevant provider repository.
To make a resource importable, refer to Extending Terraform: Resources — Import.