I would like to create ARM Template
When redeploying the template and KeyVault and the AdminPassword secret already exist, existing secret should be used.
I have found samples where KeyVault secret is used as a parameter, however this is different, because KeyVault does not exist at the time parameters are resolved.
Can you write sample ARM teplate that creates KeyVault and then uses sectets from it?
You can generate the password in the ARM Template using uniqueString.
Then create your KeyVault and the Secret. On the outputs of the KeyVault template you can then get the URI of the Secret which can be injected into the App Configuration of another resource such as a Web App. https://learn.microsoft.com/en-us/azure/app-service/app-service-key-vault-references
"outputs": {
"dbSecretUri": {
"value": "[reference(resourceId('Microsoft.KeyVault/vaults/secrets', parameters('keyVaultName'), 'yourSecretName')).secretUriWithVersion]"
}
}
Your web app will need Managed Identity enabled and the KeyVault will need to have an Access Policy that allows that app to connect to the vault.