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

执行terraform init需输入容器名称,按Azure指南操作仍遇插件连接超时

问题描述

每次执行terraform init时,会弹出以下提示要求输入容器名称:

Initializing the backend...
container_name
  The container name.

  Enter a value:

按照官方步骤创建AKS集群时,又遇到连接超时错误,无法获取Terraform Registry的提供程序包:

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/azurerm versions matching "~> 3.0"...
- Finding hashicorp/random versions matching "~> 3.0"...
- Finding hashicorp/time versions matching "0.9.1"...
- Finding azure/azapi versions matching "~> 1.5"...
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/azurerm: could not connect to registry.terraform.io: failed to request discovery document: Get
│ "https://registry.terraform.io/.well-known/terraform.json": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
╵

╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/random: could not connect to registry.terraform.io: failed to request discovery document: Get
│ "https://registry.terraform.io/.well-known/terraform.json": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
╵

╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/time: could not connect to registry.terraform.io: failed to request discovery document: Get
│ "https://registry.terraform.io/.well-known/terraform.json": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
╵

╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider azure/azapi: could not connect to registry.terraform.io: failed to request discovery document: Get
│ "https://registry.terraform.io/.well-known/terraform.json": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

解决方案

1. 消除container_name交互式输入

这个提示是因为Terraform配置中使用Azure Blob Storage作为后端存储,但未明确指定container_name参数,导致每次初始化时需要手动输入。

  • 打开你的Terraform配置文件(通常是main.tf),找到backend "azurerm"块,补充container_name字段:
terraform {
  backend "azurerm" {
    resource_group_name  = "你的资源组名称"
    storage_account_name = "你的存储账户名称"
    container_name       = "tfstate" # 自定义容器名称,比如tfstate
    key                  = "aks/terraform.tfstate"
  }
}
  • 保存配置后重新执行terraform init,就不会再弹出输入提示。

2. 解决Terraform Registry连接超时

错误核心是无法连接到官方Registry,大概率是网络受限导致,可尝试以下方法:

  • 验证网络连通性:直接访问https://registry.terraform.io/.well-known/terraform.json,确认是否能正常打开。如果无法访问,说明存在网络限制(比如公司防火墙、代理未配置)。
  • 配置代理环境变量:如果环境需要代理才能访问外网,设置对应变量:
    # Linux/macOS
    export HTTP_PROXY=http://你的代理地址:端口
    export HTTPS_PROXY=http://你的代理地址:端口
    export NO_PROXY=localhost,127.0.0.1,azure.microsoft.com
    
    # Windows PowerShell
    $env:HTTP_PROXY="http://你的代理地址:端口"
    $env:HTTPS_PROXY="http://你的代理地址:端口"
    $env:NO_PROXY="localhost,127.0.0.1,azure.microsoft.com"
    
  • 使用离线提供程序包:如果无法访问官方Registry,可手动下载所需提供程序的离线包,放到Terraform插件目录(默认路径~/.terraform.d/plugins),然后在配置中指定本地插件路径。
  • 检查防火墙规则:确认本地或网络防火墙未阻止对registry.terraform.io的443端口HTTPS请求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 07:35:19