github.com/kcburge/terraform@v0.11.12-beta1/website/docs/commands/import.html.md (about)

     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 your 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 zone ID (`Z12ABC4UGMOZ2N`). 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  * `-config=path` - Path to directory of Terraform configuration files that
    39    configure the provider for import. This defaults to your working directory.
    40    If this directory contains no Terraform configuration files, the provider
    41    must be configured via manual input or environmental variables.
    42  
    43  * `-input=true` - Whether to ask for input for provider configuration.
    44  
    45  * `-lock=true` - Lock the state file when locking is supported.
    46  
    47  * `-lock-timeout=0s` - Duration to retry a state lock.
    48  
    49  * `-no-color` - If specified, output won't contain any color.
    50  
    51  * `-provider=provider` - Specified provider to use for import. The value should be a provider
    52    alias in the form `TYPE.ALIAS`, such as "aws.eu". This defaults to the normal
    53    provider based on the prefix of the resource being imported. You usually
    54    don't need to specify this.
    55  
    56  * `-state=path` - Path to the source state file to read from. Defaults to the
    57    configured backend, or "terraform.tfstate".
    58  
    59  * `-state-out=path` - Path to the destination state file to write to. If this
    60    isn't specified the source state file will be used. This can be a new or
    61    existing path.
    62  
    63  * `-var 'foo=bar'` - Set a variable in the Terraform configuration. This flag
    64    can be set multiple times. Variable values are interpreted as
    65    [HCL](/docs/configuration/syntax.html#HCL), so list and map values can be
    66    specified via this flag. This is only useful with the `-config` flag.
    67  
    68  * `-var-file=foo` - Set variables in the Terraform configuration from
    69    a [variable file](/docs/configuration/variables.html#variable-files). If
    70    a `terraform.tfvars` or any `.auto.tfvars` files are present in the current
    71    directory, they will be automatically loaded. `terraform.tfvars` is loaded
    72    first and the `.auto.tfvars` files after in alphabetical order. Any files
    73    specified by `-var-file` override any values set automatically from files in
    74    the working directory. This flag can be used multiple times. This is only
    75    useful with the `-config` flag.
    76  
    77  ## Provider Configuration
    78  
    79  Terraform will attempt to load configuration files that configure the
    80  provider being used for import. If no configuration files are present or
    81  no configuration for that specific provider is present, Terraform will
    82  prompt you for access credentials. You may also specify environmental variables
    83  to configure the provider.
    84  
    85  The only limitation Terraform has when reading the configuration files
    86  is that the import provider configurations must not depend on non-variable
    87  inputs. For example, a provider configuration cannot depend on a data
    88  source.
    89  
    90  As a working example, if you're importing AWS resources and you have a
    91  configuration file with the contents below, then Terraform will configure
    92  the AWS provider with this file.
    93  
    94  ```hcl
    95  variable "access_key" {}
    96  variable "secret_key" {}
    97  
    98  provider "aws" {
    99    access_key = "${var.access_key}"
   100    secret_key = "${var.secret_key}"
   101  }
   102  ```
   103  
   104  You can force Terraform to explicitly not load your configuration by
   105  specifying `-config=""` (empty string). This is useful in situations where
   106  you want to manually configure the provider because your configuration
   107  may not be valid.
   108  
   109  ## Example: AWS Instance
   110  
   111  This example will import an AWS instance:
   112  
   113  ```shell
   114  $ terraform import aws_instance.foo i-abcd1234
   115  ```
   116  
   117  ## Example: Import to Module
   118  
   119  The example below will import an AWS instance into a module:
   120  
   121  ```shell
   122  $ terraform import module.foo.aws_instance.bar i-abcd1234
   123  ```