We've had an issue like this as well, because we want to use the system-assigned managed identity. Here's the issue:
Our bicep module creates a container app job, and then, creates a role assignement to the registry using an output from the container app job.
However, when creating a container app job, the deployment won't complete until the image pull has been tested. Since the role assignement depends on the container app job's creation, and thus does not exist yet, it is impossible for the deployment to finish. The system-assigned identity does not have permissions to pull yet, and the permissions won't be assigned until the container app can pull an image.
Workaround:
We've implemented a trigger that checks if an image is passed to our module. If it's not, then we use the default hello-world
image, which is public on docker hub. The deployment will complete and the role assignement will be created. Then, we redeploy, passing the image we need to the job. The pull will then succeed.
The following code has been abreviated to highlight the relevant configuration:
var defaultContainerAppJobImage = 'hello-world'
resource containerAppJobsResources 'Microsoft.App/jobs@2024-03-01' =
{
name: jobName
location: resourceGroup().location
identity: {
type: 'SystemAssigned'
}
properties: {
configuration: {
registries: containerAppJobImage == ''
? null
: [
{
server: containerRegistryServer
identity: 'system'
}
]
}
template: {
containers: [
{
image: containerAppJobImage == '' ? defaultContainerAppJobImage : containerAppJobImage
}
]
}
}
}
Recommendations:
For a container app job's deployment, testing the pull should be optional to account for this situation. Maybe the deployment could complete with a warning? Or maybe it should be possible to specify that we do not want to test the pull to confirm that the job has been deployed correctly.