Introduction
Terraform init will fail to load plugins with a permission denied or exec format error.
Error: permission denied
│ Error: Could not load plugin
│
│
│ Plugin reinitialization required. Please run "terraform init".
│
│ Plugins are external binaries that Terraform uses to access and manipulate
│ resources. The configuration provided requires plugins which can't be
│ located,
│ don't satisfy the version constraints, or are otherwise incompatible.
│
│ Terraform automatically discovers provider requirements from your
│ configuration, including providers used in child modules. To see the
│ requirements and constraints, run "terraform providers".
│
│ failed to instantiate provider "registry.terraform.io/hashicorp/aws" to
│ obtain schema: fork/exec
│ .terraform/providers/registry.terraform.io/hashicorp/aws/3.50.0/linux_amd64/terraform-provider-aws_v3.50.0-0.0.1_x4:
│ permission denied
Cause:
The provider binary permissions are likely not set as executable.
One reason that could happen is if your working directory is on a filesystem that doesn’t support executable permissions. Some reasons that might be true are if it’s mounted with the noexec
option, or if the filesystem is mounted without execute permission options such as FAT32.
You might be able to inspect the permissions by looking at a directory listing of that directory where Terraform’s provider installer cached the executable:
ls -l .terraform/providers/registry.terraform.io/hashicorp/aws/3.34.0/linux_amd64
Example command output:
total 168668
-rwxr-xr-x 1 mart mart 172716032 Apr 1 15:57 terraform-provider-aws_v3.34.0_x5
The mode in the first column of the output shows x
representing “executable”, and so this program is executable on my system. It seems like on your system it isn’t, in which case you might see some other mode pattern like -rw-r--r--
.
Resolution:
Confirm the filesystem has not been mounted with noexec option. The command below will reveal if there is a mount point with the “noexec” flag.
mount | grep noexec
If your filesystem is configured to support executable files, manually set the executable permission on the provider binary:
chmod +x .terraform/providers/registry.terraform.io/hashicorp/aws/3.34.0/linux_amd64/.terraform/providers/registry.terraform.io/hashicorp/aws/3.34.0/linux_amd64
Run the ls
command again and confirm the provider binary is now executable.
Error: exec format error
│ Error: Could not load plugin
│
│
│ Plugin reinitialization required. Please run "terraform init".
│
│ Plugins are external binaries that Terraform uses to access and manipulate
│ resources. The configuration provided requires plugins which can't be
│ located,
│ don't satisfy the version constraints, or are otherwise incompatible.
│
│ Terraform automatically discovers provider requirements from your
│ configuration, including providers used in child modules. To see the
│ requirements and constraints, run "terraform providers".
│
│ failed to instantiate provider "example.com/example/vault" to obtain schema:
│ fork/exec
│ .terraform/providers/example.com/example/vault/0.1.0/linux_amd64/terraform-provider-vault:
│ exec format error
Cause:
This error occurs when a provider binary is the wrong architecture (32 bit TF but 64 bit provider). This may indicate the provider binaries were created (compiled) on a different platform. For example executing Windows binary on Mac or vice versa. The `file` command can be used to check the OS and architecture of the file.
This error may also occur if the provider binary does not have executable permissions set. In this case you may need to manually run (chmod +x <provider>) as shown with the "could not load plugin" error type above.
Also the provider file supplied may not be the required provider binary file such as the download or unzip produced something like a plain text or html file.
Resolution:
Ensure the provider binary matches the architecture on the terraform execution machine or platform.
Here's an example list of the different architecture types for v3.63.0 of the AWS provider
https://releases.hashicorp.com/terraform-provider-aws/3.63.0/
- terraform-provider-aws_3.63.0_darwin_amd64.zip
- terraform-provider-aws_3.63.0_darwin_arm64.zip
- terraform-provider-aws_3.63.0_freebsd_386.zip
- terraform-provider-aws_3.63.0_freebsd_amd64.zip
- terraform-provider-aws_3.63.0_freebsd_arm.zip
- terraform-provider-aws_3.63.0_linux_386.zip
- terraform-provider-aws_3.63.0_linux_amd64.zip
- terraform-provider-aws_3.63.0_linux_arm.zip
- terraform-provider-aws_3.63.0_linux_arm64.zip
- terraform-provider-aws_3.63.0_windows_386.zip
- terraform-provider-aws_3.63.0_windows_amd64.zip
Also confirm file permissions are executable for the provider binary and the correct file type extension is being used.