I feel like I’m stuck in a catch 22 with how Microsoft has implemented this functionality in the Container App templates. The issue, it seems to me, is that is actually validates the secret access as part of the template deploment… which creates the issue of the Managed Identity (system) not actually yet existing since the app hasn’t been created, thus no way to assign that identity RBAC to the Keyvault, thus validation failes.
Am I missing something here, or is the process really going to require 2 templates… 1 with no secret references, just to "create" the thing, and then a second to actually properly configure it now that the managed identity is availabe?
The following field(s) are either invalid or missing. Field 'configuration.secrets' is invalid with details: 'Invalid value: "mysecret-name":
Unable to get value using Managed identity system for secret mysecret-name. Error: unable to fetch secret 'mysecret-name' using Managed identity 'system'';.
"configuration": {
"secrets": [
{
"name": "mysecret-name",
"keyVaultUrl": "[concat('https://',variables('vaultname'),'.vault.azure.net/secrets/mysecret')]",
"identity": "system"
}
]
}
2
Answers
Using a user-assigned managed identity will solve your problem:
Using Bicep, that would look like that:
key vault role assignment module:
and your main template:
Az CLI / Az Powershell supports natively bicep but you could always generate the related ARM template using
az bicep build
:One alternative is to do a nested deployment with the principalID as output to the main/master template, but i guess then yes, you do need "two" templates
ex:
or use bicep modules, here is a good sample:
https://blog.johnfolberth.com/chicken-and-the-egg-how-to-handle-bicep-interdependencies/