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/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 +}