Skip to content

fix: retry plugin cache errors in terraform_validate#996

Closed
AruneshDwivedi wants to merge 1 commit into
antonbabenko:masterfrom
AruneshDwivedi:fix/tf-validate-plugin-cache-errors
Closed

fix: retry plugin cache errors in terraform_validate#996
AruneshDwivedi wants to merge 1 commit into
antonbabenko:masterfrom
AruneshDwivedi:fix/tf-validate-plugin-cache-errors

Conversation

@AruneshDwivedi

@AruneshDwivedi AruneshDwivedi commented Jun 19, 2026

Copy link
Copy Markdown

When TF_PLUGIN_CACHE_DIR is used with parallelism (from #620), concurrent terraform validate processes can corrupt the plugin cache, causing intermittent failures.

I kept hitting this in our CI where multiple pre-commit hooks run in parallel. The errors look like:

could not retrieve the list of available versions for provider
unexpected value returned by API
plugin is cached but contents have changed
the plugin cache directory is invalid

All of these go away on retry. The existing --retry-once-with-cleanup flag already handles retrying after clearing .terraform/modules and .terraform/providers -- these errors just weren't in the match list.

This PR adds them to match_validate_errors in hooks/terraform_validate.sh. That's the same function that already catches "Module source has changed", "Could not load plugin", etc. No other changes to the init or validate flow.

After adding these patterns, our CI runs pass consistently without the 2-3 retries we were seeing before.

Related to #640

…y list

When TF_PLUGIN_CACHE_DIR is set and multiple terraform validate
processes run in parallel, the plugin cache can be in an inconsistent
state, causing errors like:

  - could not retrieve the list of available versions for provider
  - unexpected value returned by API
  - plugin is cached but contents have changed
  - the plugin cache directory is invalid

These errors are now caught by match_validate_errors and retried
via the existing --retry-once-with-cleanup mechanism.

Signed-off-by: Arunesh Dwivedi <arunesh.devops@gmail.com>
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The match_validate_errors function in hooks/terraform_validate.sh gains four new case patterns that classify provider version list API failures, unexpected API value responses, provider cache-content changes, and an invalid plugin cache directory as retryable errors (returning 1), prompting per_dir_hook_unique_part to clear cached Terraform state and re-run terraform validate.

Changes

Retryable Error Pattern Expansion

Layer / File(s) Summary
New retryable case patterns in match_validate_errors
hooks/terraform_validate.sh
Adds four case branches that return 1 for provider version list API failures, unexpected API value responses, provider cache-content changes, and invalid provider plugin cache directory errors, making them trigger the existing retry logic.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title 'fix: retry plugin cache errors in terraform_validate' directly and clearly summarizes the main change - adding retry logic for plugin cache-related errors in the terraform validation script.
Description check ✅ Passed The description provides detailed context about the plugin cache race condition, lists the specific error patterns being handled, explains the fix mechanism, and relates it to existing functionality and related issues.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@AruneshDwivedi AruneshDwivedi changed the title fix(terraform_validate): catch plugin-cache race errors in retry list fix: retry plugin cache errors in terraform_validate Jun 19, 2026
@MaxymVlasov

Copy link
Copy Markdown
Collaborator

@AruneshDwivedi AruneshDwivedi deleted the fix/tf-validate-plugin-cache-errors branch June 19, 2026 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants