使用 terraform 设置时,ACI 无法从 ACR 访问容器:InaccessibleImage

问题描述 投票:0回答:1

我正在尝试使用 terraform 设置 ACI,但正如标题所示,它似乎无法访问 ACR 注册表。

│ Error: creating Container Group (Subscription: "redacted"
│ Resource Group Name: "myresourcegoup"
│ Container Group Name: "mycontainergroup): performing ContainerGroupsCreateOrUpdate: containerinstance.ContainerInstanceClient#ContainerGroupsCreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: Code="InaccessibleImage" Message="The image 'mycompany.azurecr.io/myimage:latest' in container group 'mycontainergroup' is not accessible. Please check the image and registry credential."

这是一个重现它的最小示例:

resource "azurerm_container_group" "generic" {
  name                = local.aci_name
  location            = var.location
  resource_group_name = "myresourcegroup"
  os_type             = "Linux"
  ip_address_type     = "None"  # Specifies that no IP is assigned

  identity {
    type         = "UserAssigned"
    # real deal has the identity coming from previous steps but fails even like this
    identity_ids = ["/subscriptions/redacted/resourceGroups/myresourcegrouo/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myidentity"]

  }
  container {
    name   = local.aci_name
    image  = "mycompany.azurecr.io/myimage:latest"
    cpu    = "0.5"
    memory = "1.5"
  }
  # No ports block needed since no network access is required
}

我尝试过/检查过的事情包括但不限于:

  • 容器是可触及的,我可以使用
    docker pull
  • 很好地拉动它
  • 赋予 ACI 的身份确实为 ACR 启用了
    AcrPull
  • 当我手动授予身份更多权限,甚至完整的
    Owner
    权限时,它也会失败
  • 即使我使用 ACR 存储库中不存在的图像,或者使用无效的 ACR 存储库,我也会遇到相同的
    InaccessibleImage
    错误。
  • 如果我尝试使用无效的身份,我会收到不同的错误,所以它似乎不仅仅是忽略给定的身份
  • 用三个不同的 SotA LLM 模型+我的 2 位基础专家朋友检查了这一点 -> 没有帮助,所以变得非常绝望。仍然不想像穴居人一样从 UI 手动单击这些
azure terraform azure-container-instances azure-container-registry azure-identity
1个回答
0
投票

经典,与此斗争了很长时间,然后几乎立即偶然发现了解决方案。

显然原因是它没有使用给定的身份来向 ACR 进行身份验证,但这样做就成功了:

image_registry_credential {
    server   = "mycompany.azurecr.io"
    user_assigned_identity_id = var.identity_resource_id
  }
© www.soinside.com 2019 - 2024. All rights reserved.