Azure / Azure/bicep-types-az

Keys in key vault can't be updated via Bicep

Open
#1,906 14 comments 5 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
108
Forks
44
Avg merge
18h 53m
Merged PRs (30d)
29

Description

**Bicep version**
Bicep CLI version 0.9.1 (a2950a16df)

**Describe the bug**
Once a key with an expiration is created in key vault, the expiration date can not be updated in Bicep when performing a deployment update.
The deployment will error with the following
{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"BadRequest","message":"{\r\n \"error\": {\r\n \"code\": \"KeyCreationParametersDidNotMatchExistingKey\",\r\n \"message\": \"[KeyCreationParametersDidNotMatchExistingKey (BadRequest)] The key 'thisIsAsecret2' already exists, but the specified key creation parameters did not match that of the existing key (The existing key has an expiration date of '9/20/2022 9:26:16 AM', which doesn't match the given expiration date '9/20/2022 9:42:56 AM'.). This API can only be used for creating the first version of a new key (no subsequent versions
can be created, and existing keys cannot be updated).\"\r\n }\r\n}"}]}}

**To Reproduce**
Steps to reproduce the behavior:
1. Create the secret in exhisting KV with BICEP. az deployment group create --resource-group "rmurphyaxa-testing" --template-file main.bicep
```bicep
//~~~~~~~~~~~~~~~~~~~~ Key Vault ~~~~~~~~~~~~~~~~~//
resource keyVault 'Microsoft.KeyVault/vaults@2019-09-01' existing = {
name: 'rmurphyaxa-test-kv2'
}
//~~~~~~~~~~~~~~~~~~~~ Key ~~~~~~~~~~~~~~~~~//
resource keys 'Microsoft.KeyVault/vaults/keys@2021-11-01-preview' = {
parent: keyVault
name: 'thisIsAsecret2'
properties: {
attributes: {
enabled: true
exp: 1663666976
}
kty: 'RSA' // RSA

rotationPolicy: {
attributes: {
expiryTime: 'P28D'
}
lifetimeActions: [
{
action: {
type: 'rotate'
}
trigger: {
timeBeforeExpiry: 'P7D'
}
}
]
}
}
}
```
2. Update the properties.attributes.exp date to a later datetime. in exhisting KV with BICEP. Rerun deployment.
e.g.
```
properties: {
attributes: {
enabled: true
exp: 1663686976
}
```
4. Error will be raised stating that the secret already exists and cannot be updated.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the deployment with the provided main.bicep example and the Microsoft.KeyVault/vaults/keys@2021-11-01-preview resource type. Compare the generated resource definition with Azure Key Vault's behavior when exp changes, then inspect the corresponding type definition. Done means the issue has a verified type-definition fix or a confirmed service limitation documented with the reproduction and error.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, typescript
Domain
cloud, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.