错误:无法获取现有工作区:containers.Client#ListBlobs:

问题描述 投票:0回答:2
Error: Failed to get existing workspaces: containers.Client#ListBlobs: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="AuthorizationFailure" Message="This request is not authorized to perform this operation.\nRequestId:XXX"

我正在使用 azure 存储作为 Terraform 后端。它工作正常。我从配置中删除了存储的专用端点并应用了 terraform。它开始给我这个错误。是否需要专用端点来在 Azure 存储中存储 Terraform 状态?也不确定为什么会出现上述错误。我无法使用此错误执行 terraform init。

azure azure-devops azure-active-directory terraform terraform-provider-azure
2个回答
1
投票

我在我的环境中尝试并得到以下结果:

主要

provider  "azurerm" {
features{
resource_group {
prevent_deletion_if_contains_resources  =  false
}
}
}
provider  "azuread" {
}

data  "azurerm_resource_group"  "example" {
name  =  "< Resource group name >"
}
data  "azurerm_storage_account"  "example" {
name  =  "venkat123"
resource_group_name  =  data.azurerm_resource_group.example.name
}
terraform {
backend  "azurerm" {
resource_group_name  =  "< Resource group name >"
storage_account_name  =  "venkat123"
container_name  =  "test"
key  =  "terraform.tfstate"
}
}

在运行代码之前,请确保您已使用凭据登录:

az login --tenant <tenant ID>
az account set --subscription <subscription ID>

控制台: enter image description here

是的,您可以在没有专用端点的情况下访问存储帐户。

传送门:

enter image description here

containers.Client#ListBlobs: Failure responding to request:
StatusCode=403 -- Original Error: autorest/azure: Service returned an
error. Status=403 Code="AuthorizationFailure" Message="This request is
not authorized to perform this operation.\nRequestId:XXX"

上面的错误表明没有适当的权限来授权 azure blob 存储。

检查防火墙设置是否联网

  • 如果您是公开访问,请启用选择所有网络
  • 如果您启用了选定的网络,请添加虚拟网络。并添加您的客户端IP地址并启用
    "Allow trusted Microsoft services to access this storage account"
    允许您访问存储帐户。

enter image description here

  • 确保您拥有必要的权限,例如
    Contributor
    User Access Administrator roles
    Storage Blob Data Owner role.

参考: 使用 Terraform 在具有网络规则的存储帐户中创建 Azure 存储容器 Ansuman Bal


0
投票

我有同样的问题,Terraform 在本地工作并将状态文件保存在存储容器中,但在 AzureDevop 中使用

TerraformTaskV3@3
任务失败并出现类似错误:

│ Error: Failed to get existing workspaces: containers.Client#ListBlobs: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="AuthorizationPermissionMismatch"

所以我将

Storage Blob Data Contributor
角色分配给了我用来将 DevOps 连接到 azure 容器的服务主体。

参考:Azure Blob Storage“Authorization Permission Mismatch”error for get request with AD token

© www.soinside.com 2019 - 2024. All rights reserved.