Problem
During a plan or apply in HCP Terraform or Terraform Enterprise, the run fails during the initialization phase with the following error:
Initializing provider plugins... - Reusing previous version of hashicorp/google from the dependency lock file - Reusing previous version of hashicorp/kubernetes from the dependency lock file - Reusing previous version of hashicorp/aws from the dependency lock file - Reusing previous version of hashicorp/azurerm from the dependency lock file - Reusing previous version of hashicorp/null from the dependency lock file - Installing hashicorp/google v4.63.1... - Installed hashicorp/google v4.63.1 (signed by HashiCorp) - Installing hashicorp/kubernetes v2.20.0... - Installed hashicorp/kubernetes v2.20.0 (signed by HashiCorp) - Installing hashicorp/aws v4.65.0... - Installed hashicorp/aws v4.65.0 (signed by HashiCorp) - Installing hashicorp/azurerm v3.54.0... - Installed hashicorp/azurerm v3.54.0 (signed by HashiCorp) - Installing hashicorp/null v3.2.1... Operation failed: failed running terraform init (exit -1)
Cause
This error occurs when the terraform init process exceeds the 10-minute timeout allocated for initializing provider plugins. The primary cause is often slow network connectivity between the run agent or container and the Terraform Registry, which prevents providers from downloading in time.
Investigating the Cause
You can confirm that a timeout is the root cause by using one of the following methods.
-
Check Run Timestamps via API: Use the HCP Terraform and Terraform Enterprise Run API to inspect the
status-timestampsfor the failed run. A significant delay during theplan-initializingorapply-initializingphase indicates a timeout. -
Enable Trace Logging: Enable
TRACElevel logging for the workspace and trigger the run again. The detailed logs will show the timestamps for each provider download, making it clear where the process is delayed.
Solutions
Solution 1: Increase agent network capacity
For Terraform Enterprise environments using self-hosted agents, ensure the agent has sufficient network bandwidth and low-latency access to registry.terraform.io. Work with your network administration team to improve the agent's network performance.
Solution 2: Reduce the number of providers and modules
Review your Terraform configuration to determine if all declared providers and modules are necessary. Removing unused dependencies can reduce the number of downloads required during terraform init, which may allow the process to complete within the timeout period.
Additional Information
For more details on agent configuration and networking, refer to the official Terraform Enterprise documentation.