【问题标题】:Unauthorized error using Terraform to deploy app service on Azure使用 Terraform 在 Azure 上部署应用服务出现未经授权的错误
【发布时间】:2020-03-09 15:34:44
【问题描述】:

我正在尝试使用 Terraform 在 azure app 服务上部署一个 Windows 容器。应用服务计划部署良好,但当应用服务尝试部署时出现授权错误。我正在使用具有管理员用户和密码的 ACR 实例的连接字符串。有没有人有一些想法?

如果我从门户手动进行部署,则部署工作。

# Create an App Service Plan with Windows
resource "azurerm_app_service_plan" "appserviceplan" {
  name                = "${var.rg-name}-plan"
  location            = "westus"
  resource_group_name = var.rg-name

  # Define Windows as Host OS
  kind                = "xenon"
  is_xenon            = true

  # Choose size
  sku {
    tier = "PremiumContainer"
    size = "PC2"
  }
}

# Create an Azure Web App for Containers in that App Service Plan
resource "azurerm_app_service" "dockerapp" {
  name                = "${var.rg-name}-dockerapp"
  location            = "westus"
  resource_group_name = "${var.rg-name}"
  app_service_plan_id = "${azurerm_app_service_plan.appserviceplan.id}"

  # Configure Docker Image to load on start
  site_config {
    windows_fx_version = "DOCKER|apps.azurecr.io/test/container:latest"
  }
  app_settings = {
    # Settings for private Container Registires  
    DOCKER_REGISTRY_SERVER_URL      = "repo.azureco.io",
    DOCKER_REGISTRY_SERVER_USERNAME = "admin user",
    DOCKER_REGISTRY_SERVER_PASSWORD = "password"
  }
}

错误:

Error: Error creating App Service "dockerapp" (Resource Group "resource-group"): web.AppsClient#CreateOrUpdate: Failure sending request: StatusCode=401 -- Original Error: Code="Unauthorized" Message="Access is denied. Not authorized. latest" Details=[{"Message":"Access is denied. Not authorized. latest"},{"Code":"Unauthorized"},{"ErrorEntity":{"Code":"Unauthorized","ExtendedCode":"01001","Message":"Access is denied. Not authorized. latest","MessageTemplate":"Access is denied.","Parameters":[]}}]

【问题讨论】:

  • 显而易见的问题是 - 您确定您在 terraform 和门户网站上使用的是同一个帐户吗?或尝试清除您的 terraform 凭据并再次登录 azure

标签: azure terraform azure-web-app-service


【解决方案1】:

您可以验证DOCKER_REGISTRY_SERVER_URL 的值是否正确,它应该是一个有效的URL

例如,它在您的代码中将如下所示。

app_settings = {
    # Settings for private Container Registires  
    DOCKER_REGISTRY_SERVER_URL      = "https://apps.azurecr.io", 
    DOCKER_REGISTRY_SERVER_USERNAME = "admin user",
    DOCKER_REGISTRY_SERVER_PASSWORD = "password"
  }

如需更多参考,Here 是使用 Terraform 在 azure 应用服务上部署 Windows 容器的示例。

【讨论】:

  • 你验证了吗?您还需要注意您为 ACR 输入了正确的凭据。
  • 我没有,但是您提供的解决方案与我在工作项目中的处理方式相同,并且认为没有理由扩展您的答案,而不是试图从您那里抢走位置。我相信如果他们使用 OP,他的问题会得到解决。
【解决方案2】:

您能否快速检查 DOCKER_REGISTRY_SERVER_URL 中的 URL 是否与您在 site_config.windows_fx_version 中使用的 URL 相同

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-12
    • 1970-01-01
    相关资源
    最近更新 更多