iTranslated by AI
Fixing Intermittent Terraform Errors on M1 Mac
As stated in the title, in my environment (described below), I frequently encountered the following error when running Terraform's plan, apply, or destroy.
Environment
- PC
- M1 Mac
- OS: Big Sur
- Terraform
- tfenv
- terraform: v1.1.7
Error details
Error: Failed to load plugin schemas
│
│ Error while loading schemas for plugin components: Failed to obtain provider schema: Could not load the schema for provider
│ registry.terraform.io/hashicorp/aws: failed to instantiate provider "registry.terraform.io/hashicorp/aws" to obtain schema: Unrecognized
│ remote plugin message:
│
│ This usually means that the plugin is either invalid or simply
│ needs to be recompiled to support the latest protocol...
Error: Plugin did not respond
│
│ with provider["registry.terraform.io/hashicorp/aws"],
│ on main.tf line 1, in provider "aws":
│ 1: provider "aws" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ValidateProviderConfig call. The plugin logs may
│ contain more details.
The frustrating part of this phenomenon was that the error would sometimes occur and sometimes not...
How I resolved it
To get straight to the point, the error stopped occurring after setting the following environment variable.
GODEBUG=asyncpreemptoff=1
If you are using zsh, add the following to your ~/.zshrc.
export GODEBUG=asyncpreemptoff=1
Don't forget to run this to apply it to an already open shell: source ~/.zshrc
Path to the solution
I couldn't easily find the answer even when searching for the error message.
While looking through various issues, I found this comment in an issue.
I've had a similar issue on my M1 on Big Sur creating a few basic AWS resources. It isn't 100% reproducible yet, sometimes the apply/destroy works, sometimes it does not.
"Oh, so just like me, it works correctly sometimes."
Because of this, I was able to find the solution in a comment within the same issue.
Discussion