github.com/pdecat/terraform@v0.11.9-beta1/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. This workflow will be improved in a
    16  future version of Terraform.
    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 to Terraform:
    20  
    21  ```
    22  resource "aws_instance" "example" {
    23    # ...instance configuration...
    24  }
    25  ```
    26  
    27  The name "example" here is local to the module where it is declared and is
    28  chosen by the configuration author. This is distinct from any ID issued by
    29  the remote system, which may change over time while the resource name
    30  remains constant.
    31  
    32  If desired, you can leave the body of the resource block blank for now and
    33  return to fill it in once the instance is imported.
    34  
    35  Now `terraform import` can be run to attach an existing instance to this
    36  resource configuration:
    37  
    38  ```shell
    39  $ terraform import aws_instance.example i-abcd1234
    40  ```
    41  
    42  This command locates the AWS instance with ID `i-abcd1234` and attaches
    43  its existing settings, as described by the EC2 API, to the name
    44  `aws_instance.example` in the Terraform state.
    45  
    46  It is also possible to import to resources in child modules and to single
    47  instances of a resource with `count` set. See
    48  [_Resource Addressing_](/docs/internals/resource-addressing.html) for more
    49  details on how to specify a target resource.
    50  
    51  The syntax of the given ID is dependent on the resource type being imported.
    52  For example, AWS instances use an opaque ID issued by the EC2 API, but
    53  AWS Route53 Zones use the domain name itself. Consult the documentation for
    54  each importable resource for details on what form of ID is required.
    55  
    56  As a result of the above command, the resource is recorded in the state file.
    57  You can now run `terraform plan` to see how the configuration compares to
    58  the imported resource, and make any adjustments to the configuration to
    59  align with the current (or desired) state of the imported object.
    60  
    61  ## Complex Imports
    62  
    63  The above import is considered a "simple import": one resource is imported
    64  into the state file. An import may also result in a "complex import" where
    65  multiple resources are imported. For example, an AWS security group imports
    66  an `aws_security_group` but also one `aws_security_group_rule` for each rule.
    67  
    68  In this scenario, the secondary resources will not already exist in
    69  configuration, so it is necessary to consult the import output and create
    70  a `resource` block in configuration for each secondary resource. If this is
    71  not done, Terraform will plan to destroy the imported objects on the next run.
    72  
    73  If you want to rename or otherwise move the imported resources, the
    74  [state management commands](/docs/commands/state/index.html) can be used.