Ad space (banner)
AD

Got the fundamentals? A structured Terraform course is a fast way to level up.

Find Terraform courses on Udemy

Affiliate link. Costs you nothing extra.

Lesson 31 / 37

Adopting Existing Resources with terraform import

When something already exists and you want Terraform to manage it, use terraform import. It records an existing resource into state.

The syntax is terraform import address id, where the ID is the resource's real identifier in the cloud.

Running terraform import aws_instance.web i-0123456789abcdef0 puts that existing instance under the address aws_instance.web.

A common stumble is importing without first writing a matching resource block. Import fills in state, not configuration — the block must already exist, or the next plan proposes destroying what you just imported.

In real work, import is how infrastructure built by hand is gradually brought under Terraform's management, without rebuilding it.

Terraform
Try it (type this into the pseudo terminal)
terraform import aws_instance.web i-0123456789abcdef0

🧑‍💻 You can type this command into the Terraform pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)