github.com/loicalbertin/terraform@v0.6.15-0.20170626182346-8e2583055467/website/docs/import/usage.html.md (about)

     1  ---
     2  layout: "docs"
     3  page_title: "Import: Usage"
     4  sidebar_current: "docs-import-usage"
     5  description: |-
     6    The `terraform import` command is used to import existing infrastructure.
     7  ---
     8  
     9  # Import Usage
    10  
    11  The `terraform import` command is used to import existing infrastructure.
    12  
    13  The command currently can only import one resource at a time. This means
    14  you can't yet point Terraform import to an entire collection of resources
    15  such as an AWS VPC and import all of it. A future version of Terraform will
    16  be able to do this.
    17  
    18  To import a resource, first write a resource block for it in your
    19  configuration, establishing the name by which it will be known in Terraform:
    20  
    21  ```
    22  resource "aws_instance" "bar" {
    23    # ...instance configuration...
    24  }
    25  ```
    26  
    27  If desired, you can leave the body of the resource block blank for now and
    28  return to fill it in once the instance is imported.
    29  
    30  Now `terraform import` can be run to attach an existing instance to this
    31  resource configuration:
    32  
    33  ```shell
    34  $ terraform import aws_instance.bar i-abcd1234
    35  ```
    36  
    37  The above command imports an AWS instance with the given ID and attaches
    38  it to the name `aws_instance.bar`. You can also import resources into modules.
    39  See the [resource addressing](/docs/internals/resource-addressing.html)
    40  page for more details on the full range of addresses supported.
    41  
    42  The ID given is dependent on the resource type being imported. For example,
    43  AWS instances use their direct IDs. However, AWS Route53 zones use the
    44  domain name itself. Console the resource documentation for details on what
    45  form of ID each resource expects.
    46  
    47  As a result of the above command, the resource is recorded in the state file.
    48  You can now run `terraform plan` to see how the configuration compares to
    49  the imported resource, and make any adjustments to the configuration to
    50  align with the current (or desired) state of the imported object.
    51  
    52  ## Complex Imports
    53  
    54  The above import is considered a "simple import": one resource is imported
    55  into the state file. An import may also result in a "complex import" where
    56  multiple resources are imported. For example, an AWS security group imports
    57  an `aws_security_group` but also one `aws_security_group_rule` for each rule.
    58  
    59  In this scenario, the secondary resources will not already exist in
    60  configuration, so it is necessary to consult the import output and create
    61  a `resource` block in configuration for each secondary resource. If this is
    62  not done, Terraform will plan to destroy the imported objects on the next run.
    63  
    64  If you want to rename or otherwise modify the imported resources, the
    65  [state management commands](/docs/commands/state/index.html) can be used.