Resource Type to get existing certificates from Microsoft.KeyVault is missing
- Dominant language
- Bicep
- Stars
- 3.6k
- Forks
- 830
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 79
Description
**Bicep version**
Bicep CLI version 0.7.4 (5afc312467)
**Describe the bug**
There is no resource type available to query existing `certificate` from `Microsoft.KeyVault/vaults`.
Seeing some old issues https://github.com/Azure/bicep/issues/5630, it seems `Microsoft.KeyVault/vaults/certificates@2019-09-01` was present. Is it replaced by something else?
May not be related but I do not see any [alias here in PSRule.Rules.Azure](https://github.com/Azure/PSRule.Rules.Azure/blob/main/data/providers/microsoft.keyvault/types.json) to get Certificate information such as SAN etc, so most likely it never exists or removed.
Basically, we are using `existing` Custom Certificate in Azure FD CDN from KeyVault. We want to get `secretVersion` and `subjectAlternativeNames` from it and pass to `Microsoft.Cdn/profiles/secrets@2021-06-01`, or otherwise we need to hard code these values to avoid deployment drifts. Updating these two properties manually would be additional step to update Azure CDN Bicep templates whenever there is latest version of Certificate available. As we set `useLatestVersion: true`, not getting this value in runtime or not updating bicep with these value, will result in drift between Bicep and deployed config whenever we try to run deployment.
Though this drift which say one resource to modify does not do anything, but it looks confusing and not desirable.
Example:
```js
~ Microsoft.Cdn/profiles/static-stg/secrets/cdn-byoc-certificate [2021-06-01]
- properties.parameters.secretVersion: "528c4xxxxxxxxxxxxxxx5b2f6a820"
- properties.parameters.subjectAlternativeNames: [
0: "static.example.com"
1: "static-azur.example.com"
2: "static-azur-stg.example.com"
3: "static-exp1.example.com"
4: "static-exp2.example.com"
5: "static-exp3.example.com"
6: "static-afd.example.com"
7: "static-afd-stg.example.com"
8: "static-afd-test.example.com"
]
Resource changes: 1 to modify, 23 no change, 3 to ignore.
```
OR
if `useLatestVersion` is set to `true`, deployment should not show changes available for `modify` wrt `secretVersion` and `subjectAlternativeNames`
**To Reproduce**
Create a file cdn.bicep:
```js
@sys.description('KeyVault name for Custom certificate for custom domains')
param keyVaultName string
@sys.description('KeyVault name Subscription Id')
param keyVaultSubscriptionId string
@sys.description('KeyVault name resource group name')
param keyVaultResourceGroup string
@sys.description('KeyVault secret name for custom domain')
param keyVaultSecretName string
var secretSource = '/subscriptions/${keyVaultSubscriptionId}/resourceGroups/${keyVaultResourceGroup}/providers/Microsoft.KeyVault/vaults/${keyVaultName}/secrets/${keyVaultSecretName}'
@sys.description('Attach Custom Certificate from Key Vault')
resource cdn_custom_cert_secret 'Microsoft.Cdn/profiles/secrets@2021-06-01' = {
parent: cdn_profile
name: 'cdn-byoc-certificate'
properties: {
parameters: {
type: 'CustomerCertificate'
secretSource: {
id: secretSource
}
useLatestVersion: true
}
}
}
```
If we run this, it will always show `Resource changes: 1 to modify` which is change in [properties.parameters.secretVersion](https://github.com/Azure/PSRule.Rules.Azure/blob/main/data/providers/microsoft.cdn/types.json#L2054) and [properties.parameters.subjectAlternativeNames ](https://github.com/Azure/PSRule.Rules.Azure/blob/main/data/providers/microsoft.cdn/types.json#L2057)
Contributor guide
Research direction
Start with the cdn.bicep reproduction and compare the Microsoft.Cdn/profiles/secrets@2021-06-01 properties with the referenced Key Vault certificate resource type. Review the linked PSRule.Rules.Azure types.json entries for Microsoft.KeyVault and Microsoft.Cdn. Done means the certificate values can be obtained without hard-coding, or useLatestVersion no longer produces a spurious modification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100