Documentation Index
Fetch the complete documentation index at: https://mintlify.com/hashicorp/terraform/llms.txt
Use this file to discover all available pages before exploring further.
Command: import
Theterraform import command imports existing infrastructure resources into Terraform, allowing you to manage them with Terraform going forward.
Usage
Options
-
-config=path- Path to a directory of Terraform configuration files to use to configure the provider. Defaults to the current working directory. If no config files are present, they must be provided via the input prompts or environment variables. -
-input=false- Disable interactive input prompts. -
-lock=false- Don’t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace. -
-lock-timeout=DURATION- Duration to retry a state lock. Default is0s(zero seconds), which causes immediate failure if the lock is already held by another process. -
-no-color- If specified, output won’t contain any color. -
-var 'NAME=VALUE'- Set a value for one of the input variables in the root module of the configuration. Use this option multiple times to set more than one variable. This is only useful with the-configflag. -
-var-file=FILENAME- Set values for potentially many input variables declared in the root module of the configuration, using definitions from a “tfvars” file. Use this option multiple times to include values from more than one file. -
-ignore-remote-version- A rare option used for the remote backend only. See the remote backend documentation for more information.
terraform import also accepts the legacy options -state, -state-out, and -backup.
Example
Import an AWS EC2 instance:Provider Configuration
Terraform will attempt to load configuration files that configure the provider being used for import. If no configuration files are present, you must provide configuration for the provider through environment variables or by specifying the-config flag.
The -var and -var-file flags can be used to provide values for variables in the provider configuration.
Example: Import into Resource
First, write a resource block for it in your configuration, using aresource block:
terraform import can be run to attach an existing instance to this resource configuration: