|
| 1 | +--- |
| 2 | +layout: "docs" |
| 3 | +page_title: "Command: import" |
| 4 | +sidebar_current: "docs-commands-import" |
| 5 | +description: |- |
| 6 | + The `terraform import` command is used to import existing resources into Terraform. |
| 7 | +--- |
| 8 | + |
| 9 | +# Command: import |
| 10 | + |
| 11 | +The `terraform import` command is used to |
| 12 | +[import existing resources](/docs/import/index.html) |
| 13 | +into Terraform. |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +Usage: `terraform import [options] ADDRESS ID` |
| 18 | + |
| 19 | +Import will find the existing resource from ID and import it into your Terraform |
| 20 | +state at the given ADDRESS. |
| 21 | + |
| 22 | +ADDRESS must be a valid [resource address](/docs/internals/resource-addressing.html). |
| 23 | +Because any resource address is valid, the import command can import resources |
| 24 | +into modules as well directly into the root of yor state. |
| 25 | + |
| 26 | +ID is dependent on the resource type being imported. For example, for AWS |
| 27 | +instances it is the instance ID (`i-abcd1234`) but for AWS Route53 zones |
| 28 | +it is the domain. Please reference the provider documentation for details |
| 29 | +on the ID format. If you're unsure, feel free to just try an ID. If the ID |
| 30 | +is invalid, you'll just receive an error message. |
| 31 | + |
| 32 | +The command-line flags are all optional. The list of available flags are: |
| 33 | + |
| 34 | +* `-backup=path` - Path to backup the existing state file. Defaults to |
| 35 | + the `-state-out` path with the ".backup" extension. Set to "-" to disable |
| 36 | + backups. |
| 37 | + |
| 38 | +* `-input=true` - Whether to ask for input for provider configuration. |
| 39 | + |
| 40 | +* `-state=path` - The path to read and save state files (unless state-out is |
| 41 | + specified). |
| 42 | + |
| 43 | +* `-state-out=path` - Path to write the final state file. By default, this is |
| 44 | + the state path. |
| 45 | + |
| 46 | +## Provider Configuration |
| 47 | + |
| 48 | +To access the provider that the resource is being imported from, Terraform |
| 49 | +will ask you for access credentials. If you don't want to be asked for input, |
| 50 | +verify that all environment variables for your provider are set. |
| 51 | + |
| 52 | +The import command cannot read provider configuration from a Terraform |
| 53 | +configuration file. |
| 54 | + |
| 55 | +## Example: AWS Instance |
| 56 | + |
| 57 | +This example will import an AWS instance: |
| 58 | + |
| 59 | +``` |
| 60 | +$ terraform import aws_instance.foo i-abcd1234 |
| 61 | +``` |
| 62 | + |
| 63 | +## Example: Import to Module |
| 64 | + |
| 65 | +The example below will import an AWS instance into a module: |
| 66 | + |
| 67 | +``` |
| 68 | +$ terraform import module.foo.aws_instance.bar i-abcd1234 |
| 69 | +``` |
0 commit comments