Problem
When running a terraform apply in Terraform Enterprise, the operation fails with one of the following error messages:
-
no suitable version installed(Terraform CLI 0.12 and earlier) -
Could not load plugin(Terraform CLI 0.13 and later)
This typically occurs during a run that is intended to destroy the last remaining resources managed by a specific provider.
Cause
Terraform Enterprise runs plan and apply operations in separate, isolated execution environments. Each environment runs terraform init independently.
When you remove all resources associated with a provider from your configuration files, the terraform init command during the apply phase no longer detects a need for that provider and does not install its plugin. However, the state file still contains the resources that need to be destroyed, and destroying them requires the provider plugin. This mismatch between the configuration and the state causes the apply to fail because the necessary plugin is not available in the apply environment.
Solutions
There are two solutions depending on the version of the Terraform CLI in use.
Solution 1: For Terraform CLI 0.12.20 and later
This approach uses a required_providers block to explicitly tell Terraform to install the necessary provider plugin during the apply phase.
- Examine the apply output to identify the required provider. The provider name appears in the error message.
-
Create a new configuration file (e.g.,
versions.tf) and add arequired_providersblock for the missing provider. Thesourceandversionarguments help ensure the correct provider is installed.terraform { required_providers { ## Replace "aws" with the name of the missing provider. aws = { source = "hashicorp/aws" version = ">= 3.0" } } } - Queue a new run. The apply should now succeed, and the latest state version will no longer contain references to the destroyed resources.
- Remove the temporary configuration file you created in step 2. The workspace is now in a clean state.
Solution 2: For Terraform CLI 0.12.19 and earlier
The required_providers block is not available in these older versions of Terraform. To resolve the issue, you must perform state manipulation to remove the resources from the state file directly and then clean up the backend infrastructure resources manually.
Refer to the guide on Modifying Terraform states in Terraform Enterprise or HCP Terraform for detailed instructions on this procedure.
Additional Information
The error Could not load plugin can also occur after upgrading from Terraform CLI 0.12 to 0.13. If this applies to your situation, please review the Plugin reinitialization error after upgrade to Terraform 0.13 article for more information.