terraform import
Bringing an existing, hand-made object under Terraform management by recording it in state against a resource address.
In more detail
Since Terraform 1.5 you write an import block with the object's identifier and the target address, and the next plan shows the import before it happens. Import only records ownership: it creates nothing, and you must still write matching configuration, or generate a draft with plan -generate-config-out. The older terraform import command writes to state immediately without a plan.
Example
import {
to = aws_vpc.main
id = "vpc-0abc123"
}Related terms
- Terraform state — Terraform's record, usually a JSON file called terraform.tfstate, mapping each resource in the configuration to the real object it created.
- Terraform resource — A resource block, which asks Terraform to create and manage one piece of infrastructure such as a network, file or database.
- terraform plan — The command that compares configuration, state and reality and prints the actions needed to make them match, without changing anything.
Taught in
- What State Really Is And Why It Is Needed — Infrastructure as Code with Terraform
- Simulating A Managed Database — Infrastructure as Code with Terraform
- Detecting And Fixing Configuration Drift — Infrastructure as Code with Terraform
- Importing Existing Resources — Infrastructure as Code with Terraform
- Forcing Replacement — Infrastructure as Code with Terraform
- The Plan That Wanted To Destroy Production — HashiCorp Terraform Associate (004) Exam Prep
- One Hour, No Weights Published — HashiCorp Terraform Associate (004) Exam Prep
- State: Terraform's Memory Of What It Built — HashiCorp Terraform Associate (004) Exam Prep
- Drift: When Reality Stops Matching State — HashiCorp Terraform Associate (004) Exam Prep
- Importing What Terraform Did Not Build — HashiCorp Terraform Associate (004) Exam Prep
- Moved And Removed Blocks: Refactoring Without Rebuilding — HashiCorp Terraform Associate (004) Exam Prep
- Inspecting And Repairing State From The CLI — HashiCorp Terraform Associate (004) Exam Prep
- Runs In HCP Terraform: The cloud Block And Remote Execution — HashiCorp Terraform Associate (004) Exam Prep