'Terraform fails to create Azure Container Instance because the image is inaccessible

In my main.tf I have the following resource;

resource "azurerm_container_group" "auth_container_group" {
  name                = "foocg"
  location            = "UK South"
  resource_group_name = "foorg"

  ip_address_type = "public"
  dns_name_label  = "fooapi"
  os_type         = "Linux"

  image_registry_credential {
    username = "foo"
    password = "notMyRealPassword"
    server   = "foo.azurecr.io"
  }

  container {
    name   = "foo"
    image  = "foo:${var.imagebuild}" //also tried "foo.azurecr.io/foo:${var.imagebuild}"
    cpu    = "1"
    memory = "1"

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

I have built a CD pipeline in Azure Devops. If I use a public image repository the resource is created and I can view my api, the build succeeds. As soon as I swap to a private repository I get the following error in the pipeline output log;

Error: creating/updating Container Group: (Name "foocg" / Resource Group "foorg"): containerinstance.ContainerGroupsClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InaccessibleImage" Message="The image 'foo:417' in container group 'foocg' is not accessible. Please check the image and registry credential.

I have tried using a private docker hub registry, and an Azure Container registry, the latter I have enabled admin user in order to get the login details.

Could anyone suggest what I might be doing wrong and what I might do to fix this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source