---
Title: Import resources
URL Source: https://company-skill.com/p/terraform/terraform-import-resources
Language: en
Description: You have cloud resources (like an ECS instance or OSS bucket) that were created outside Terraform—manually, via console, or with scripts—and now you want Terraform to manage them without recreating…
---

# Import resources

Part of **Terraform**. Route queries via `POST https://company-skill.com/api/route`.

## What You Want to Do

You have cloud resources (like an ECS instance or OSS bucket) that were created outside Terraform—manually, via console, or with scripts—and now you want Terraform to manage them without recreating or disrupting them. This requires aligning your configuration with the actual resource and updating Terraform state safely.

**Typical User Questions**:
- How do I import existing cloud resources into Terraform?
- Can I start managing legacy infrastructure with Terraform?

## Decision Tree

Pick the best path for your situation:

- **If** you are importing **1–5 existing resources** and can manually write `main.tf` configurations → Use terraform import (go to *terraform/terraform-instance*)
- **If** you encounter errors like **state lock conflict**, **configuration drift**, **undefined variable**, **dependency cycle**, or **provider authentication failure** during or after import → Use (go to *terraform/terraform-iac*)
- **Otherwise (default)** → Start with ** terraform import **, as it’s the foundational method for initial adoption of existing resources.

## Path Comparison

| Path | Best For | Complexity | Code Required | Automation | Key Fact | Detail Skill |
|------|----------|------------|---------------|------------|----------|-------------|
| terraform import | medium | Yes | No | Only supports one resource at a time; requires exact resource ID and resource address | `terraform/guide/terraform-instance` |
| ID | medium | Yes | No | Diagnoses issues like state lock conflict and configuration drift but does not perform import itself | `terraform/troubleshooting/terraform-iac` |

## Path Details

### Path 1: terraform import 

**Brief Description**: This approach uses the `terraform import` command to register an existing cloud resource into Terraform state. You must first define the resource block in `main.tf`, then run `terraform import <resource address> <resource ID>`. After import, use `terraform show` to verify state and remove any read-only properties that cause drift.

**Key technical facts**:
- Prerequisites: Terraform runtime environment (Cloud Shell or custom developer environment), read-only permissions for relevant resources, Terraform version v1.5.0 or later for import block feature, Terraform and terraform-provider-alicloud installed for Terraformer tools

**When to Use**:
- 1-5Terraform

### Path 2: Console / Dashboard
**Best For**: ID 

**Brief Description**: This path focuses on troubleshooting common failures during or after using `terraform import`. It leverages commands like `terraform plan`, `terraform force-unlock`, and environment variable `TF_LOG=DEBUG` to diagnose issues such as state lock conflict, configuration drift, undefined variable, dependency cycle, and provider authentication failure.

**Key technical facts**:
- Prerequisites: Terraform, Terraform, Terraform

**When to Use**:
- 'Error acquiring the state lock'
- terraform plan

## FAQ

Q: Which path should I start with?
A: Start with ** terraform import ** if you’re new to importing and have fewer than 5 resources. Only switch to the troubleshooting path if you hit specific errors like state lock conflict or configuration drift.

Q: What if I need to import 50 ECS instances but used terraform import ?
A: You’ll face extreme manual overhead—each instance requires individual `terraform import` calls and hand-edited `main.tf` blocks. The process is error-prone and not scalable, as noted in its limitations.

Q: What if I encounter a state lock conflict but chose terraform import without troubleshooting knowledge?
A: Your import will fail with "Error acquiring the state lock", and you won’t know to use `terraform force-unlock` or check backend locking mechanisms—leading to stalled workflows.

Q: Can I avoid removing read-only properties after import?
A: No. If you leave read-only properties (like `create_time` or `status`) in your `main.tf`, `terraform plan` will detect configuration drift and propose unintended changes. Removal is mandatory for stable management.

Q: Does the troubleshooting path help if my resource address is wrong?
A: Indirectly—it may reveal mismatches via `terraform plan` showing unexpected deletions or creations, but correcting the resource address itself is part of the initial import setup, not troubleshooting.

Q: Is TF_LOG=DEBUG useful during initial import?
A: Yes, especially when facing silent failures or provider authentication failure. Setting `TF_LOG=DEBUG` reveals low-level API calls and credential resolution steps, aiding diagnosis even during first-time imports.

## Related queries

import existing resources, import legacy infrastructure, terraform manage existing, bring under terraform, adopt existing resource, terraform import command, how to import resource, can terraform manage existing, import ecs instance, import oss bucket, terraform state import, manage existing resourc

---
Part of [Terraform](https://company-skill.com/p/terraform.md) · https://company-skill.com/llms.txt
