安装第三方Terraform Provider插件失败,请求技术协助
Terraform Provider安装超时问题排查方案
问题复现
执行terraform init时出现以下超时错误:
Error: Failed to install provider Error while installing gavinbunney/kubectl v1.14.0: could not query provider registry for registry.terraform.io/gavinbunney/kubectl: failed to retrieve authentication checksums for provider: the request failed after 2 attempts, please try again later: Get "https://github.com/gavinbunney/terraform-provider-kubectl/releases/download/v1.14.0/terraform-provider-kubectl_1.14.0_SHA256SUMS": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) Error: Failed to install provider Error while installing gavinbunney/bitbucketserver v1.7.1: could not query provider registry for registry.terraform.io/gavinbunney/bitbucketserver: failed to retrieve authentication checksums for provider: the request failed after 2 attempts, please try again later: Get "https://github.com/gavinbunney/terraform-provider-bitbucketserver/releases/download/v1.7.1/terraform-provider-bitbucketserver_1.7.1_SHA256SUMS": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
当前使用的providers.tf配置:
terraform { required_providers { bitbucketserver = { source = "gavinbunney/bitbucketserver" version = "~> 1.5" } kubectl = { source = "gavinbunney/kubectl" version = "~> 1.14.0" } } }
排查与解决步骤
1. 验证网络连通性
- 直接访问报错中的SHA256SUMS链接,确认是否能正常加载内容
- 检查本地网络是否存在防火墙、代理或VPN限制,导致无法访问GitHub资源;必要时临时关闭限制或调整网络路由
2. 手动安装Provider
如果网络问题无法快速解决,可手动下载并部署Provider:
- 前往对应Provider的GitHub仓库,下载对应版本的二进制包及SHA256SUMS文件
- 验证下载文件的哈希值,确保文件完整性:
将输出值与SHA256SUMS文件中的对应条目对比,确认一致# 以kubectl provider为例,替换为你的系统架构包名 shasum -a 256 terraform-provider-kubectl_1.14.0_darwin_amd64.zip - 将Provider文件放到Terraform的本地插件目录,目录结构需匹配:
注:替换# 全局插件目录示例(Linux/macOS) ~/.terraform.d/plugins/registry.terraform.io/gavinbunney/kubectl/1.14.0/darwin_amd64/ # 或当前项目本地目录 ./terraform/plugins/registry.terraform.io/gavinbunney/kubectl/1.14.0/darwin_amd64/darwin_amd64为你的系统架构(如linux_amd64、windows_amd64)
3. 延长Terraform请求超时时间
在providers.tf中添加client_timeout配置,延长请求等待时间:
terraform { required_providers { bitbucketserver = { source = "gavinbunney/bitbucketserver" version = "~> 1.5" } kubectl = { source = "gavinbunney/kubectl" version = "~> 1.14.0" } } client_timeout = "5m" # 可根据网络情况调整,如10m }
修改后重新执行terraform init
4. 配置Provider镜像加速
针对国内网络环境,可通过配置Terraform镜像源加速Provider下载:
- 环境变量方式:设置
TF_REGISTRY_MIRROR指向镜像地址 - 配置文件方式:在
~/.terraformrc(Linux/macOS)或%APPDATA%\terraform.rc(Windows)中添加:provider_installation { network_mirror { url = "镜像源地址" } }
内容的提问来源于stack exchange,提问作者needhelp
相关产品推荐
相关产品推荐

