# Error: Resource precondition failed: All preconditions must be met

- **ID:** `terraform/lifecycle-precondition-failed`
- **Domain:** terraform
- **Category:** assertion_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

A lifecycle precondition block in a resource configuration evaluated to false during the plan or apply phase.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.5.0 | active | — | — |
| 1.6.0 | active | — | — |
| 1.7.0 | active | — | — |
| 1.8.0 | active | — | — |

## Workarounds

1. **Inspect the precondition condition expression. For example, if precondition { condition = var.instance_count > 0 error_message = "Instance count must be positive" } fails, set var.instance_count to a positive value. Use terraform console to test the condition: terraform console then evaluate var.instance_count > 0.** (90% success)
   ```
   Inspect the precondition condition expression. For example, if precondition { condition = var.instance_count > 0 error_message = "Instance count must be positive" } fails, set var.instance_count to a positive value. Use terraform console to test the condition: terraform console then evaluate var.instance_count > 0.
   ```
2. **If the precondition depends on data source output, ensure the data source is correctly configured and returns expected values. Add a depends_on to the data source if needed.** (85% success)
   ```
   If the precondition depends on data source output, ensure the data source is correctly configured and returns expected values. Add a depends_on to the data source if needed.
   ```
3. **Temporarily remove or modify the precondition to allow the apply to proceed, then fix the root cause and re-add the precondition.** (75% success)
   ```
   Temporarily remove or modify the precondition to allow the apply to proceed, then fix the root cause and re-add the precondition.
   ```

## Dead Ends

- **Comment out the precondition block and re-apply without fixing the underlying condition.** — The precondition exists to enforce an invariant; bypassing it may lead to incorrect infrastructure state. (70% fail)
- **Change the precondition condition to always true without understanding why it failed.** — This defeats the purpose of the precondition and masks real issues. (90% fail)
- **Run terraform plan -refresh-only to update state before applying.** — Preconditions are evaluated during plan; refresh-only doesn't change the logical condition causing the failure. (80% fail)
