Azure Portal PowerShell下Terraform init查询provider包失败问题求助
问题根因
- 资源类型前缀错误:当前你使用的
azurermprovider所有资源命名规则为azurerm_<资源类型>,你配置中写的azure_storage_account、azure_storage_container等资源前缀为azure_,对应已经废弃的旧版azureprovider,该provider已从Terraform官方registry下架,因此Terraform检索不到对应安装包报错。 - 资源引用语法错误:存储容器配置中
storage_account_name = azure.storage.account.lab.name写法不符合Terraform资源引用规则,正确写法为azurerm_storage_account.lab.name。 - 资源属性错误:存储blob配置中
account_replication_type = "Block"属性写错,块blob的对应属性为blob_type = "Block"。
修复后的完整配置
terraform { required_providers { azurerm = { source = "hashicorp/azurerm" version = "=2.74.0" } } } provider "azurerm" { features {} } resource "azurerm_storage_account" "lab" { name = "newbloddystoragegroup" resource_group_name = "TFResourcegroup" location = "eastus" account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "lab" { name = "blobcontainer4dev" storage_account_name = azurerm_storage_account.lab.name container_access_type = "private" } resource "azurerm_storage_blob" "lab" { name = "TerraformdevBlob" storage_account_name = azurerm_storage_account.lab.name storage_container_name = azurerm_storage_container.lab.name blob_type = "Block" # 块blob需要根据实际使用场景补充source/content/content_md5三个属性中的任意一个,比如指定本地文件路径: # source = "./本地文件路径" } resource "azurerm_storage_share" "lab"{ name = "terraformdevshare" storage_account_name = azurerm_storage_account.lab.name quota = 50 }
后续操作步骤
- 删除当前目录下的
.terraform文件夹和.terraform.lock.hcl文件,清除旧的依赖缓存 - 执行
terraform init即可正常初始化
内容的提问来源于stack exchange,提问作者Mick8695
相关产品推荐
相关产品推荐

