What's the best way to handle key vault creation in Bicep with soft deletion and purge protection? #10656
-
In Terraform, it's possible to enable automatic recovery of deleted key vaults and secrets if they are soft deleted. If it's a new key vault or secret, it'll choose to create it instead. However, in Bicep, it's a bit more tricky. Here we have to specify This is a problem for us, especially with development environments where we sometimes delete resources and create them again. We can't set createMode to recover unconditionally, because it'll cause new environments not currently deployed to fail, as well as if we add new key vaults to the bicep project. There's a couple of issues reported, that if resolved, would completely fix this issue for us: But until (if ever) these are resolved, what's the best way to approach this? When we potentially have a mix of soft-deleted and non-existing key vaults that must be either recovered or created, this seems very cumbersome. Any good tips here? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I don't think there is a good "declarative" approach here. I assume if it's set to recover and it's new, then it fails? Hopefully you are not using access policies anyway, RBAC is a better model in most circumstances. The fallback would be to add a restore function in a deploymentScript, which skips action if the vault isn't soft deleted or restores if it was. Then run that Module, before you're normal keyvault Module. If this is for a lab, I would just disable soft delete all together. What scenario do you find yourself in need of this? How often are people deleting vaults? Perhaps consider a delete lock as an alternative. Or let the deployment fail, then run a manual restore command, then redeploy. |
Beta Was this translation helpful? Give feedback.
-
totally agree, it's a nightmare try to avoid colissions with existing or not |
Beta Was this translation helpful? Give feedback.
I don't think there is a good "declarative" approach here.
I assume if it's set to recover and it's new, then it fails? Hopefully you are not using access policies anyway, RBAC is a better model in most circumstances.
The fallback would be to add a restore function in a deploymentScript, which skips action if the vault isn't soft deleted or restores if it was.
Then run that Module, before you're normal keyvault Module.
If this is for a lab, I would just disable soft delete all together.
What scenario do you find yourself in need of this? How often are people deleting vaults? Perhaps consider a delete lock as an alternative.
Or let the deployment fail, then run a manual restore command, th…