Interview Prep/Terraform/Partial Applies, Version Mismatches and CI Failures

`terraform test` fails with `Error: Test assertion failed` in CI, while the same `.tftest.hcl` passes locally.

IntermediateTroubleshootingPartial Applies, Version Mismatches and CI Failures
Answer

Likely causes → Tests with command = apply create real resources and depend on credentials/region/account quotas; local runs use different variables; leftover resources from a previous failed run conflict.

Diagnose → terraform test -verbose to see the plan/apply inside each run block; check for orphaned test resources by tag.

Fix → Pass explicit variables in the test file, use unique names per run (for example a random_id in a setup module), and clean orphans.

Prevent → Use command = plan and mocked providers (mock_provider, Terraform 1.7+) for most unit tests; reserve apply tests for a dedicated test account.

All Terraform questions

More on Partial Applies, Version Mismatches and CI Failures