Terraform's design assumes that each remote object in Terraform's care is bound to one resource instance and one alone. If the same object is bound to multiple instances then confusing behavior will often result, such as two resource configurations competing to update a single object, or objects being "left behind" when all existing Terraform deployments are destroyed. This assumption was previously only implied, though. This change is an attempt to be more explicit about it, although these are additions to some older documentation sections that have not been revised for some time and so this is just a best effort to make this information discoverable without getting drawn into a full-on reorganization of these sections. While revising this there were some particular oddities that I decided to revise while I was there, but I'll leave a fuller revision of this older content for a later commit when we have more time to review it in greater detail.
2.1 KiB
layout, page_title, sidebar_current, description
| layout | page_title | sidebar_current | description |
|---|---|---|---|
| docs | Import | docs-import | Terraform is able to import existing infrastructure. This allows you take resources you've created by some other means and bring it under Terraform management. |
Import
For a hands-on tutorial, try the Import Terraform Configuration guide on HashiCorp Learn.
Terraform is able to import existing infrastructure. This allows you take resources you've created by some other means and bring it under Terraform management.
This is a great way to slowly transition infrastructure to Terraform, or to be able to be confident that you can use Terraform in the future if it potentially doesn't support every feature you need today.
~> Warning: Terraform expects that each remote object it is managing will be bound to only one resource address, which is normally guaranteed by Terraform itself having created all objects. If you import existing objects into Terraform, be careful to import each remote object to only one Terraform resource address. If you import the same object multiple times, Terraform may exhibit unwanted behavior. For more information on this assumption, see the State section.
Currently State Only
The current implementation of Terraform import can only import resources into the state. It does not generate configuration. A future version of Terraform will also generate configuration.
Because of this, prior to running terraform import it is necessary to write
manually a resource configuration block for the resource, to which the
imported object will be mapped.
While this may seem tedious, it still gives Terraform users an avenue for importing existing resources.
You can follow the Terraform Import guide on HashiCorp learn for a hands-on
introduction to using the terraform import command.