I am implementing a bicep file for deploying an API management with a custom domain. The certificated related to this custom domain must be taken from a keyvault.
I’ve managed to get it working using the following hardcoded values:
hostnameConfigurations: [{
type: 'Proxy'
hostName: 'my-url.my-domain.com'
keyVaultId: <secret-identifier-from-certificate-in-keyvault>
certificateSource: 'KeyVault'
defaultSslBinding: true
negotiateClientCertificate: false
}]
The value of ‘secret-identifier-from-certificate-in-keyvault’ is taken as it comes from the keyvault certificate
However, after this test, I want to do this automated, so that if I provide the certificate name and the keyvault ID I am able to retrieve this data, as it is different in each environment.
I’ve tried accessing the certificate data like this:
resource keyVaultCertificate 'Microsoft.KeyVault/vaults/certificates@2022-07-01' existing = {
parent: keyVault
name: certificateName
}
and then using the corresponding value in the bicep keyVaultId: keyVaultCertificate.id
but didn’t work.
Also, same with secret:
resource keyVaultSecret 'Microsoft.KeyVault/vaults/secrets@2022-07-01' existing = {
parent: keyVault
name: certificateName
}
And using keyVaultId: keyVaultSecret.id
, also without success, getting error ‘Invalid parameter: Not a valid KeyVault secret Url’
How could I get the same data I see in the certificate from the azure portal, but as part of my bicep?
Also, I’ve read that it is better not to include the version in the keyVaultId
data so that it works when the certificate is renewed. Could someone shed some light on how to do this considering also this best practice?
Thanks
2
Answers
After some extra research, I've come up to a working solution, although it is not what I expected, as I intended to retrieve the whole secret address as a property of the certificate.
If I concatenate the keyvault address with the certificate data like this:
Then the certificate is attached properly to the custom domain field in the api management.
Also as it does not include the version, it is supposed to be taking the last one so if renovated, it should keep working.
try
kvSecret.properties.secretUri
when usingkeyVaultId
Below is a draft template.