You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行Terraform init命令后出现“Failed to query available providers”错误求助

Terraform初始化报错:hashicorp/ami provider不存在

执行terraform init及terraform init -upgrade时均出现以下错误:

PS C:\Users\D~\master_terraform\01_aws> terraform init -upgrade

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/aws versions matching "~> 4.0"...
- Finding latest version of hashicorp/ami...
- Installing hashicorp/aws v4.39.0...
- Installed hashicorp/aws v4.39.0 (signed by HashiCorp)
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/ami: provider registry registry.terraform.io
│ does not have a provider named registry.terraform.io/hashicorp/ami
│
│ All modules should specify their required_providers so that external consumers will get the correct providers when
│ using a module. To see which modules are currently depending on hashicorp/ami, run the following command:
│     terraform providers
PS C:\Users\D~\master_terraform\01_aws> terraform init

Initializing the backend...

Initializing provider plugins...
- Reusing previous version of hashicorp/aws from the dependency lock file
- Finding latest version of hashicorp/ami...
- Using previously-installed hashicorp/aws v4.31.0
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/ami: provider registry registry.terraform.io
│ does not have a provider named registry.terraform.io/hashicorp/ami
│
│ All modules should specify their required_providers so that external consumers will get the correct providers when
│ using a module. To see which modules are currently depending on hashicorp/ami, run the following command:
│     terraform providers
╵

期望命令能顺利完成初始化,以便应用基础设施配置。


解决方法

  • 定位引用来源:执行terraform providers命令,找到哪个模块或本地配置中引用了hashicorp/ami provider。
  • 修正配置:
    • 本地配置场景:检查required_providers块,删除对hashicorp/ami的声明;若需获取AMI信息,改用hashicorp/aws provider下的aws_ami数据源。
    • 第三方模块场景:确认模块是否存在配置错误,替换为正确的模块版本或修正模块内的provider声明。
  • 更新依赖锁:删除当前目录下的.terraform.lock.hcl文件,确保新的依赖关系被正确锁定。
  • 重新初始化:再次执行terraform init或terraform init -upgrade完成初始化。

内容的提问来源于stack exchange,提问作者thickthumb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 12:01:46