Skip to content

Commit 9b8dff8

Browse files
authored
Enhancing Shared Example (#27)
* enhance imports-exports example - added a new user define type for Tags in the shared.bicep export example.
1 parent 60a5d2a commit 9b8dff8

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

bicep-examples/imports-exports/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The import and export feature in Bicep allows you to reuse commonly used variabl
66

77
Instead of manually defining a variable in every new Bicep file, such as:
88

9-
`var budgetAlertEmail = 'dan@rios.engineer'`
9+
`var budgetAlertEmail = 'dan@rios.engineer'`
1010

1111
You can store this value centrally and simply import it into your template when needed.
1212

@@ -37,7 +37,7 @@ var location = 'uksouth'
3737
var branchOfficePublicIP = '82.110.72.90'
3838
```
3939

40-
### Entra example:
40+
### Entra example
4141

4242
```bicep
4343
@export()
@@ -57,13 +57,15 @@ var entraSecurityGroups = {
5757
}
5858
}
5959
```
60+
6061
## Import Examples
6162

6263
To import variables and types from your shared/central file you can use the `import as name` function to either import everything (*) or a specific variable (see branch office example below).
6364

6465
Once imported to the file, your Bicep intellisense will show your auto completion for your import name with all the available variables and types to use in the current template file.
6566

6667
### Entra ObjectId
68+
6769
```bicep
6870
import * as shared from 'shared.bicep'
6971
@@ -77,7 +79,8 @@ roleAssignments: [
7779
]
7880
```
7981

80-
### ACL IP Example:
82+
### ACL IP Example
83+
8184
```bicep
8285
import * as shared from 'shared.bicep'
8386
// or you can only import the required variable vs all available via
@@ -116,4 +119,4 @@ or PowerShell
116119
Connect-AzAccount
117120
Set-AzContext -Subscription "subscription name or id"
118121
New-AzResourceGroupDeployment -Confirm -ResourceGroup "your-rg" -TemplateFile "main.bicep" -TemplateParameterFile "main.bicepparam"
119-
```
122+
```

bicep-examples/imports-exports/main.bicep

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ targetScope = 'subscription'
55
import * as shared from 'shared.bicep'
66
// import { location } as location from 'shared.bicep' to only import a specific var or type from the file.
77

8+
// MARK: Parameters
9+
@description('Tags for the resources')
10+
param tags shared.tagsType
11+
812
// MARK: Variables
913
var location = shared.location // using central value from shared.bicep
1014
var rgName = 'rg-bicepify-demo'
@@ -22,6 +26,7 @@ module resourceGroupShared 'br/public:avm/res/resources/resource-group:0.4.1' =
2226
roleDefinitionIdOrName: 'Contributor'
2327
}
2428
]
29+
tags: tags
2530
}
2631
}
2732

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using 'main.bicep'
2+
3+
param tags = {
4+
Environment: 'Dev'
5+
CostCentre: 'IT'
6+
Owner: 'Contoso'
7+
BusinessUnit: 'DevOps'
8+
'hidden-title': 'Stack'
9+
}

bicep-examples/imports-exports/shared.bicep

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,12 @@ var branchOfficePublicIP = '82.110.72.90'
2626
@export()
2727
@description('Azure Websites Private DNS Zone FQDN')
2828
var azureWebsitesPrivateDnsZone = 'privatelink.azurewebsites.net'
29+
30+
@export()
31+
type tagsType = {
32+
Environment: 'Prod' | 'Dev' | 'Test'
33+
CostCentre: string
34+
Owner: string
35+
BusinessUnit: string
36+
*: string
37+
}

0 commit comments

Comments
 (0)