Import state verification in Terraform - Time & Space Complexity
When Terraform imports resources, it checks the current state to match real infrastructure.
We want to know how the time needed grows as we import more resources.
Analyze the time complexity of the following import verification steps.
resource "aws_instance" "example" {
# resource config
}
terraform import aws_instance.example i-1234567890abcdef0
terraform state show aws_instance.example
This sequence imports a resource and verifies its state matches the real instance.
Look at what happens repeatedly when importing multiple resources.
- Primary operation: API call to fetch resource details for each import
- How many times: Once per resource imported
Each resource import triggers one API call to verify state.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 API calls |
| 100 | 100 API calls |
| 1000 | 1000 API calls |
Pattern observation: The number of API calls grows directly with the number of resources.
Time Complexity: O(n)
This means the time to verify state grows in a straight line as you add more resources.
[X] Wrong: "Importing many resources only takes a fixed amount of time regardless of count."
[OK] Correct: Each resource needs a separate check, so time grows with how many you import.
Understanding how operations scale helps you plan and explain infrastructure changes clearly.
"What if Terraform cached resource states locally? How would that affect the time complexity of import verification?"