azure - 在 Azure 部署的 terraform 计划上获取状态代码 403

标签 azure terraform

我正在尝试在 Azure 上部署带有数据库的 Web 应用程序,但尽管对 Azure 中租户的凭据进行了双重/三次检查,但似乎无法使其正常工作。尝试创建新的客户端 secret ,但无论如何都不起作用。

无法列出提供程序注册状态,这可能是由于凭据无效或服务主体无权使用资源管理器 API,Azure 错误:resources.ProvidersClient#List:响应请求失败:StatusCode =403 -- 原始错误:autorest/azure:服务返回错误。状态 = 403 代码 =“授权失败”消息 =“客户端 '########-########-########-########- ########' 对象 ID '########-########-########-########-# #######' 无权在范围 '/subscriptions/########-########- 上执行操作 'Microsoft.Resources/subscriptions/providers/read' ########-########-########' 或范围无效。如果最近授予了访问权限,请刷新您的凭据。”

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "=3.0.0"
    }
  }
}

provider "azurerm" {
  features {}
  subscription_id = var.subscription_id
  client_id = var.client_id
  client_secret = var.client_secret
  tenant_id = var.tenant_id
}

resource "azurerm_resource_group" "example" {
  name     = "azure-tf-bgapp"
  location = "West Europe"
}

resource "azurerm_container_group" "example" {
  name                = "bgapp-tf"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  ip_address_type     = "Public"
  dns_name_label      = "aci-label"
  os_type             = "Linux"

  container {
    name   = "bgapp-web"
    image  = "shekeriev/bgapp-web"
    cpu    = "0.5"
    memory = "1.5"

    ports {
      port = 80
      protocol = "TCP"
    }
  }

  container {
    name   = "bgapp-web"
    image  = "shekeriev/bgapp-db"
    cpu    = "0.5"
    memory = "1.5"
    environment_variables = {
      "MYSQL_ROOT_PASSWORD" = "Password1"
    }
  }
  tags = {
    environment = "bgapp"
  }
}

最佳答案

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

最初我尝试了相同的代码,但在我的环境中遇到了相同的错误。

控制台:

enter image description here

出现上述错误是由于您的(服务主体)没有执行该操作所需的权限(授权)。

Owner 等角色分配给服务主体代码后,成功运行。

转至门户 -> 订阅 -> 访问控制 (IAM) -> 添加角色分配 -> 所有者 -> 添加您的服务主体 -> 审核 + 创建。

enter image description here

在我执行 terraform 代码后,它执行得非常完美。

控制台:

enter image description here

门户: enter image description here

关于azure - 在 Azure 部署的 terraform 计划上获取状态代码 403,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74733837/

相关文章:

azure - 从 Azure Active Directory 中的多个租户获取用户详细信息

amazon-web-services - 如何在 Terraform 中将 EBS 卷添加到 ECS 实例

terraform - 无服务器框架 CORS 无法部署到 AWS CloudFormation

terraform - 缺少配置版本 Terraform Cloud

google-cloud-platform - 尝试在 GCP 中模拟服务帐户时出现错误 403、 "The caller does not have permission"

Azure管道 secret 变量不适用于PR触发器

azure - 我对云服务的部署有点困惑,特别是是否可以只替换代码

terraform - Terraform 中的 Azure SQL 备份设置

azure - 无法在 Azure Cloud Shell (CLI) 中为持久帐户文件创建存储

azure - 将 Dropbox 文件内容从逻辑应用传递到 Azure 函数