Skip to content

Commit

Permalink
kv multi-env condition example addition
Browse files Browse the repository at this point in the history
  • Loading branch information
riosengineer committed Aug 14, 2024
1 parent 16dbe53 commit 5807a12
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
8 changes: 8 additions & 0 deletions bicep-examples/conditions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ param kvEnv string = 'prod'
var kvSku = kvEnv == 'prod' ? 'premium' : 'standard'
```
In addition, you can use conditions to determine if certain parameters are true or false depending on the enviornment you are deploying to. For example, in the second Key Vault example within `main.bicep`:
```javascript
enablePurgeProtection: env == 'preprod' || env == 'prod' ? true : false
```
Will only enable purge protection on a Key Vault if the enviornment is `preprod` or `prod`. Therefore, if you were deploying the Key Vault to `dev` the Key Vault would not have purge protection enabled. This type of conditon can be expanded to other parameters and objects such as Azure App Service slots, etc.
## 🚀 Deployment
> [!NOTE]
Expand Down
21 changes: 19 additions & 2 deletions bicep-examples/conditions/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ param location string = resourceGroup().location
@description('Azure Key Vault resource names that will be created. Must be globally unique.')
param kvName string = 'kv-uks-bicepify-prod-001'

@description('Azure Key Vault resource names that will be created. Must be globally unique.')
param kvName2 string = 'kv-uks-bicepify-prod-002'

@description('Deploy Azure Key Vault true/false.')
param deployResource bool = false

Expand All @@ -19,10 +22,10 @@ param deployResource bool = false
'preprod'
'dev'
])
param kvEnv string = 'prod'
param env string = 'prod'

// Environment variable for Key Vault SKU else if
var kvSku = kvEnv == 'prod' ? 'premium' : 'standard'
var kvSku = env == 'prod' ? 'premium' : 'standard'

module KeyVault 'br/public:avm/res/key-vault/vault:0.7.0' = if (deployResource) {
name: '${uniqueString(deployment().name, location)}-${kvName}'
Expand All @@ -36,3 +39,17 @@ module KeyVault 'br/public:avm/res/key-vault/vault:0.7.0' = if (deployResource)

// Output Key Vault name
output kvUri string = KeyVault.outputs.name

// Multi-enviornment condition param example
module KeyVault2 'br/public:avm/res/key-vault/vault:0.6.2' = {
name: '${uniqueString(deployment().name, location)}-kv'
params: {
name: kvName
location: location
enablePurgeProtection: env == 'preprod' || env == 'prod' ? true : false
enableSoftDelete: true
softDeleteRetentionInDays: 7
enableRbacAuthorization: true
sku: kvSku
}
}

0 comments on commit 5807a12

Please sign in to comment.