The apply we interrupted and the resources state never heard about
Описание и применение
Перерванный запуск Terraform оставил ресурсы в облаке, но не в состоянии, создавая дубли и лишние расходы. Внедрение динамических таймаутов, безопасных шагов и процедуры восстановления после прерывания устраняет эти проблемы.
Задача
An interrupted Terraform apply left resources partially created, causing orphan resources and state inconsistencies, leading to unexpected costs and failed subsequent runs.
Результат
The new process prevents orphan resources, eliminates duplicate NAT gateways, and keeps costs predictable by ensuring state reflects reality after interruptions.
Рабочий процесс
- 1. Run Terraform apply with dynamic timeout and cancellation‑safe step marking.
- 2. If apply is interrupted, run
terraform refreshto sync state with actual resources. - 3. Execute
terraform planto identify differences between state and real resources. - 4. Import any existing resources missing from state using
terraform import. - 5. Re‑run
terraform applyto apply remaining changes. - 6. Weekly: run a sweep script that lists resources with the workspace tag and compares them against state to detect forgotten resources.
Доказательства
Terraform does not roll anything back when you kill it. Resources that were created before the process died exist in the cloud; whether they exist in state depends on whether the state write completed.
We also run a weekly sweep that lists resources carrying our workspace tag and compares them against state, which is how you find things Terraform has forgotten it owns.
- Дата записи: 2026-09-15T22:15:52.830Z