-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
targetScope = 'resourceGroup' | ||
|
||
// Metadata | ||
metadata name = 'Key Vault creation Bicep module' | ||
metadata description = 'Showcasing Azure Bicep if conditions' | ||
metadata owner = '[email protected]' | ||
|
||
// Parameters | ||
@description('Azure region for deployments chosen from the resource group.') | ||
param location string = resourceGroup().location | ||
|
||
|
@@ -30,7 +32,7 @@ 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}' | ||
params: { | ||
name: kvName | ||
name: kvName2 | ||
location: location | ||
sku: kvSku | ||
enableSoftDelete: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Azure Bicep - User Defined Types | ||
|
||
## Introduction | ||
|
||
User-defined types in Azure Bicep allow you to create custom data structures within your Bicep templates. Instead of relying solely on built-in data types, you can define your own types tailored to your specific needs and requirements. | ||
|
||
## 📃 Benefits of User Defined Types | ||
|
||
✅ Type Safety: User-defined types (UDTs) enforce that only valid data structures are used. This helps prevent accidental misconfigurations. | ||
|
||
✅ Maintainability: When you adopt UDTs, your Bicep code becomes easier to maintain. Changes to the types automatically propagate to all places where the type is used. | ||
|
||
✅ Intellisense: The VS Code Bicep IntelliSense provides type auto completions and expected values, enhancing your development experience. | ||
|
||
## User Defined Type Example | ||
|
||
In this example, you’ll deploy a Storage Account using custom types as part of the configuration. Within the `main.bicep` file, you’ll find the two defined types: | ||
|
||
```bicep | ||
// User Defined Types | ||
type storageSkuType = 'Premium_LRS' | 'Premium_ZRS' | 'Standard_GRS' | 'Standard_GZRS' | 'Standard_LRS' | 'Standard_RAGRS' | 'Standard_RAGZRS' | 'Standard_ZRS' | ||
type storageConfType = { | ||
name: string | ||
sku: storageSkuType | ||
location: string | ||
kind: 'StorageV2' | 'BlobStorage' | 'FileStorage' | 'BlockBlobStorage' } | ||
``` | ||
|
||
By defining the data structure in this way, you ensure both type safety and valid data for the Storage Account configuration. | ||
|
||
Next, the Bicep parameter is defined for the type. | ||
|
||
```bicep | ||
@description('Storage account UDR param config.') | ||
param storageConf storageConfType | ||
``` | ||
|
||
Lastly, using the parameter you can complete the Storage Account config `storageConf.sku` `storageConf.kind` and so forth. | ||
|
||
## 🚀 Deployment | ||
|
||
> [!NOTE] | ||
> You need to have a resource group deployed before trying this out. | ||
In VisualStudio Code open a terminal and run: | ||
|
||
CLI | ||
|
||
```bash | ||
az login | ||
az account set --subscription 'subscription name or id' | ||
az deployment group create -g 'your-rg' --confirm-with-what-if -f '.\main.bicep' -p 'main.bicepparam' | ||
``` | ||
|
||
or PowerShell | ||
|
||
```powershell | ||
Connect-AzAccount | ||
Set-AzContext -Subscription "subscription name or id" | ||
New-AzResourceGroupDeployment -Confirm -ResourceGroup "your-rg" -TemplateFile "main.bicep" -TemplateParameterFile "main.bicepparam" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
targetScope = 'resourceGroup' | ||
|
||
// Metadata | ||
metadata name = 'User Defined Types' | ||
metadata description = 'Showcasing Azure Bicep UDTs' | ||
metadata owner = '[email protected]' | ||
|
||
// User Defined Types | ||
type storageSkuType = 'Premium_LRS' | 'Premium_ZRS' | 'Standard_GRS' | 'Standard_GZRS' | 'Standard_LRS' | 'Standard_RAGRS' | 'Standard_RAGZRS' | 'Standard_ZRS' | ||
|
||
type storageConfType = { | ||
name: string | ||
sku: storageSkuType | ||
location: string | ||
kind: 'StorageV2' | 'BlobStorage' | 'FileStorage' | 'BlockBlobStorage' } | ||
|
||
// Parameters | ||
@description('Azure region used from the resource group.') | ||
param location string = resourceGroup().location | ||
|
||
@description('Storage account UDR param config.') | ||
param storageConf storageConfType | ||
|
||
// Storage Account | ||
module storage 'br/public:avm/res/storage/storage-account:0.11.1' = { | ||
name: 'uniqueString(deployment().name, location)-st' | ||
params: { | ||
name: storageConf.name | ||
location: location | ||
skuName: storageConf.sku | ||
kind: storageConf.kind | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using 'main.bicep' | ||
|
||
param storageConf = { | ||
name: 'stbicepifyudt001' | ||
sku: 'Standard_LRS' | ||
location: 'uksouth' | ||
kind: 'StorageV2' | ||
} |