Problem
When running a plan in HCP Terraform or Terraform Enterprise, the run fails with a timeout error when attempting to access a remote module registry.
Error: Error accessing remote module registry Failed to retrieve available versions for module "example" from tfe.mywebsite.com: net/http: request canceled (Client.Timeout or context cancellation while reading body).
Cause
This error occurs when the HTTP request from Terraform to the remote module registry exceeds the default client timeout. This is common when the remote registry is slow to respond or experiencing high latency due to network conditions.
Solution
You can resolve this issue by increasing the client timeout period. Set the TF_REGISTRY_CLIENT_TIMEOUT environment variable in the affected workspace to a value greater than the default of 10 seconds.
Procedure
Follow these steps to set the environment variable in your HCP Terraform or Terraform Enterprise workspace.
- Navigate to the workspace where you are experiencing the timeout error.
- Select the Variables tab from the workspace's menu.
- Under the Environment Variables section, select Add variable.
- Configure the new environment variable with the following details:
- Key:
TF_REGISTRY_CLIENT_TIMEOUT - Value:
20(or a higher value in seconds, as needed) - Ensure the Category is set to
Environment variable.
- Key:
- Select Save variable.
- Queue a new plan in the workspace to apply the change. Terraform will now use the extended timeout when communicating with the module registry.