From c02f9bf25d15968a35b249fd86ed432966189d55 Mon Sep 17 00:00:00 2001 From: Dan Rios <36534747+riosengineer@users.noreply.github.com> Date: Sat, 26 Jul 2025 20:07:11 +0100 Subject: [PATCH 1/3] enhance imports-exports example Updated the 'imports-exports' example to include a tags parameter, updated the main.bicep to use it, and added a main.bicepparam file for parameterization. Minor formatting improvements were made to the README. --- bicep-examples/imports-exports/README.md | 11 +++++++---- bicep-examples/imports-exports/main.bicep | 5 +++++ bicep-examples/imports-exports/main.bicepparam | 9 +++++++++ bicep-examples/key-vault/README.md | 0 bicep-examples/key-vault/deploy.ps1 | 0 bicep-examples/key-vault/example-deployment.bicep | 0 bicep-examples/key-vault/keyvault.bicep | 0 bicep-examples/key-vault/keyvault.bicepparam | 0 8 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 bicep-examples/imports-exports/main.bicepparam create mode 100644 bicep-examples/key-vault/README.md create mode 100644 bicep-examples/key-vault/deploy.ps1 create mode 100644 bicep-examples/key-vault/example-deployment.bicep create mode 100644 bicep-examples/key-vault/keyvault.bicep create mode 100644 bicep-examples/key-vault/keyvault.bicepparam diff --git a/bicep-examples/imports-exports/README.md b/bicep-examples/imports-exports/README.md index 3379ff0..564fc79 100644 --- a/bicep-examples/imports-exports/README.md +++ b/bicep-examples/imports-exports/README.md @@ -6,7 +6,7 @@ The import and export feature in Bicep allows you to reuse commonly used variabl Instead of manually defining a variable in every new Bicep file, such as: - `var budgetAlertEmail = 'dan@rios.engineer'` + `var budgetAlertEmail = 'dan@rios.engineer'` You can store this value centrally and simply import it into your template when needed. @@ -37,7 +37,7 @@ var location = 'uksouth' var branchOfficePublicIP = '82.110.72.90' ``` -### Entra example: +### Entra example ```bicep @export() @@ -57,6 +57,7 @@ var entraSecurityGroups = { } } ``` + ## Import Examples 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). @@ -64,6 +65,7 @@ To import variables and types from your shared/central file you can use the `imp 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. ### Entra ObjectId + ```bicep import * as shared from 'shared.bicep' @@ -77,7 +79,8 @@ roleAssignments: [ ] ``` -### ACL IP Example: +### ACL IP Example + ```bicep import * as shared from 'shared.bicep' // or you can only import the required variable vs all available via @@ -116,4 +119,4 @@ or PowerShell Connect-AzAccount Set-AzContext -Subscription "subscription name or id" New-AzResourceGroupDeployment -Confirm -ResourceGroup "your-rg" -TemplateFile "main.bicep" -TemplateParameterFile "main.bicepparam" -``` \ No newline at end of file +``` diff --git a/bicep-examples/imports-exports/main.bicep b/bicep-examples/imports-exports/main.bicep index 4f4f57a..c58f30e 100644 --- a/bicep-examples/imports-exports/main.bicep +++ b/bicep-examples/imports-exports/main.bicep @@ -5,6 +5,10 @@ targetScope = 'subscription' import * as shared from 'shared.bicep' // import { location } as location from 'shared.bicep' to only import a specific var or type from the file. +// MARK: Parameters +@description('Tags for the resources') +param tags shared.tagsType + // MARK: Variables var location = shared.location // using central value from shared.bicep var rgName = 'rg-bicepify-demo' @@ -22,6 +26,7 @@ module resourceGroupShared 'br/public:avm/res/resources/resource-group:0.4.1' = roleDefinitionIdOrName: 'Contributor' } ] + tags: tags } } diff --git a/bicep-examples/imports-exports/main.bicepparam b/bicep-examples/imports-exports/main.bicepparam new file mode 100644 index 0000000..a098191 --- /dev/null +++ b/bicep-examples/imports-exports/main.bicepparam @@ -0,0 +1,9 @@ +using 'main.bicep' + +param tags = { + Environment: 'Dev' + CostCentre: 'IT' + Owner: 'Contoso' + BusinessUnit: 'DevOps' + 'hidden-title': 'Stack' +} diff --git a/bicep-examples/key-vault/README.md b/bicep-examples/key-vault/README.md new file mode 100644 index 0000000..e69de29 diff --git a/bicep-examples/key-vault/deploy.ps1 b/bicep-examples/key-vault/deploy.ps1 new file mode 100644 index 0000000..e69de29 diff --git a/bicep-examples/key-vault/example-deployment.bicep b/bicep-examples/key-vault/example-deployment.bicep new file mode 100644 index 0000000..e69de29 diff --git a/bicep-examples/key-vault/keyvault.bicep b/bicep-examples/key-vault/keyvault.bicep new file mode 100644 index 0000000..e69de29 diff --git a/bicep-examples/key-vault/keyvault.bicepparam b/bicep-examples/key-vault/keyvault.bicepparam new file mode 100644 index 0000000..e69de29 From c7feaee5cf91bb91b32e25906919a5e8d3d0a5d2 Mon Sep 17 00:00:00 2001 From: Dan Rios <36534747+riosengineer@users.noreply.github.com> Date: Sat, 26 Jul 2025 20:07:54 +0100 Subject: [PATCH 2/3] Remove KV Removing GitHub Demo --- bicep-examples/key-vault/README.md | 0 bicep-examples/key-vault/deploy.ps1 | 0 bicep-examples/key-vault/example-deployment.bicep | 0 bicep-examples/key-vault/keyvault.bicep | 0 bicep-examples/key-vault/keyvault.bicepparam | 0 5 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 bicep-examples/key-vault/README.md delete mode 100644 bicep-examples/key-vault/deploy.ps1 delete mode 100644 bicep-examples/key-vault/example-deployment.bicep delete mode 100644 bicep-examples/key-vault/keyvault.bicep delete mode 100644 bicep-examples/key-vault/keyvault.bicepparam diff --git a/bicep-examples/key-vault/README.md b/bicep-examples/key-vault/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/bicep-examples/key-vault/deploy.ps1 b/bicep-examples/key-vault/deploy.ps1 deleted file mode 100644 index e69de29..0000000 diff --git a/bicep-examples/key-vault/example-deployment.bicep b/bicep-examples/key-vault/example-deployment.bicep deleted file mode 100644 index e69de29..0000000 diff --git a/bicep-examples/key-vault/keyvault.bicep b/bicep-examples/key-vault/keyvault.bicep deleted file mode 100644 index e69de29..0000000 diff --git a/bicep-examples/key-vault/keyvault.bicepparam b/bicep-examples/key-vault/keyvault.bicepparam deleted file mode 100644 index e69de29..0000000 From f6fc3c0e15c5727a5fd58a7d2b27acbdc1c96950 Mon Sep 17 00:00:00 2001 From: Dan Rios <36534747+riosengineer@users.noreply.github.com> Date: Sat, 26 Jul 2025 20:14:21 +0100 Subject: [PATCH 3/3] Export tagsType type definition in shared.bicep Added an exported tagsType object type with standard tagging properties and support for additional custom tags. This enables consistent tagging across Bicep modules. --- bicep-examples/imports-exports/shared.bicep | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bicep-examples/imports-exports/shared.bicep b/bicep-examples/imports-exports/shared.bicep index 687f540..affc69f 100644 --- a/bicep-examples/imports-exports/shared.bicep +++ b/bicep-examples/imports-exports/shared.bicep @@ -26,3 +26,12 @@ var branchOfficePublicIP = '82.110.72.90' @export() @description('Azure Websites Private DNS Zone FQDN') var azureWebsitesPrivateDnsZone = 'privatelink.azurewebsites.net' + +@export() +type tagsType = { + Environment: 'Prod' | 'Dev' | 'Test' + CostCentre: string + Owner: string + BusinessUnit: string + *: string +}