Skip to content

Commit

Permalink
kv multi-env condition example addition (#23)
Browse files Browse the repository at this point in the history
* kv multi-env condition example addition

* Excluding REPOSITORY_GRYPE from ML
  • Loading branch information
riosengineer authored Aug 14, 2024
1 parent 16dbe53 commit 14c3c2e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
DISABLE: COPYPASTE,SPELL # Uncomment to disable copy-paste and spell checks
DISABLE_LINTERS: YAML_V8R,YAML_YAMLLINT,YAML_PRETTIER,REPOSITORY_CHECKOV,POWERSHELL_POWERSHELL,ACTION_ACTIONLINT,REPOSITORY_GITLEAKS
DISABLE_LINTERS: YAML_V8R,YAML_YAMLLINT,YAML_PRETTIER,REPOSITORY_CHECKOV,POWERSHELL_POWERSHELL,ACTION_ACTIONLINT,REPOSITORY_GITLEAKS,REPOSITORY_GRYPE
REPOSITORY_KICS_DISABLE_ERRORS: true

# Upload MegaLinter artifacts
Expand Down
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 14c3c2e

Please sign in to comment.