Skip to content

Commit 93db1db

Browse files
Merge pull request #242263 from mumian/0620-reference-function
Add addintioal information for reference()
2 parents 2f2be6c + b4475a6 commit 93db1db

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

articles/azure-resource-manager/bicep/bicep-functions-resource.md

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: mumian
55
ms.author: jgao
66
ms.topic: conceptual
77
ms.custom: devx-track-bicep
8-
ms.date: 09/09/2022
8+
ms.date: 06/20/2023
99
---
1010

1111
# Resource functions for Bicep
@@ -68,7 +68,7 @@ param allowedLocations array = [
6868
'australiacentral'
6969
]
7070
71-
resource policyDefinition 'Microsoft.Authorization/policyDefinitions@2019-09-01' = {
71+
resource policyDefinition 'Microsoft.Authorization/policyDefinitions@2021-06-01' = {
7272
name: 'locationRestriction'
7373
properties: {
7474
policyType: 'Custom'
@@ -88,7 +88,7 @@ resource policyDefinition 'Microsoft.Authorization/policyDefinitions@2019-09-01'
8888
}
8989
}
9090
91-
resource policyAssignment 'Microsoft.Authorization/policyAssignments@2019-09-01' = {
91+
resource policyAssignment 'Microsoft.Authorization/policyAssignments@2022-06-01' = {
9292
name: 'locationAssignment'
9393
properties: {
9494
policyDefinitionId: policyDefinition.id
@@ -146,7 +146,7 @@ param adminLogin string
146146
@secure()
147147
param adminPassword string
148148
149-
resource sqlServer 'Microsoft.Sql/servers@2020-11-01-preview' = {
149+
resource sqlServer 'Microsoft.Sql/servers@2022-08-01-preview' = {
150150
...
151151
}
152152
```
@@ -161,7 +161,7 @@ param subscriptionId string
161161
param kvResourceGroup string
162162
param kvName string
163163
164-
resource keyVault 'Microsoft.KeyVault/vaults@2019-09-01' existing = {
164+
resource keyVault 'Microsoft.KeyVault/vaults@2023-02-01' existing = {
165165
name: kvName
166166
scope: resourceGroup(subscriptionId, kvResourceGroup )
167167
}
@@ -234,7 +234,7 @@ Other `list` functions have different return formats. To see the format of a fun
234234
The following example deploys a storage account and then calls `listKeys` on that storage account. The key is used when setting a value for [deployment scripts](../templates/deployment-script-template.md).
235235

236236
```bicep
237-
resource storageAccount 'Microsoft.Storage/storageAccounts@2019-06-01' = {
237+
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
238238
name: 'dscript${uniqueString(resourceGroup().id)}'
239239
location: location
240240
kind: 'StorageV2'
@@ -243,7 +243,7 @@ resource storageAccount 'Microsoft.Storage/storageAccounts@2019-06-01' = {
243243
}
244244
}
245245
246-
resource dScript 'Microsoft.Resources/deploymentScripts@2019-10-01-preview' = {
246+
resource dScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
247247
name: 'scriptWithStorage'
248248
location: location
249249
...
@@ -325,9 +325,9 @@ The possible uses of `list*` are shown in the following table.
325325
| Microsoft.DevTestLab/labs/schedules | [ListApplicable](/rest/api/dtl/schedules/listapplicable) |
326326
| Microsoft.DevTestLab/labs/users/serviceFabrics | [ListApplicableSchedules](/rest/api/dtl/servicefabrics/listapplicableschedules) |
327327
| Microsoft.DevTestLab/labs/virtualMachines | [ListApplicableSchedules](/rest/api/dtl/virtualmachines/listapplicableschedules) |
328-
| Microsoft.DocumentDB/databaseAccounts | [listConnectionStrings](/rest/api/cosmos-db-resource-provider/2022-05-15/database-accounts/list-connection-strings) |
329-
| Microsoft.DocumentDB/databaseAccounts | [listKeys](/rest/api/cosmos-db-resource-provider/2022-05-15/database-accounts/list-keys) |
330-
| Microsoft.DocumentDB/databaseAccounts/notebookWorkspaces | [listConnectionInfo](/rest/api/cosmos-db-resource-provider/2022-05-15/notebook-workspaces/list-connection-info) |
328+
| Microsoft.DocumentDB/databaseAccounts | [listConnectionStrings](/rest/api/cosmos-db-resource-provider/2022-11-15/database-accounts/list-connection-strings) |
329+
| Microsoft.DocumentDB/databaseAccounts | [listKeys](/rest/api/cosmos-db-resource-provider/2022-11-15/database-accounts/list-keys) |
330+
| Microsoft.DocumentDB/databaseAccounts/notebookWorkspaces | [listConnectionInfo](/rest/api/cosmos-db-resource-provider/2022-11-15/notebook-workspaces/list-connection-info) |
331331
| Microsoft.DomainRegistration | [listDomainRecommendations](/rest/api/appservice/domains/listrecommendations) |
332332
| Microsoft.DomainRegistration/topLevelDomains | [listAgreements](/rest/api/appservice/topleveldomains/listagreements) |
333333
| Microsoft.EventGrid/domains | [listKeys](/rest/api/eventgrid/controlplane-version2022-06-15/domains/list-shared-access-keys) |
@@ -354,9 +354,9 @@ The possible uses of `list*` are shown in the following table.
354354
| Microsoft.Logic/workflows/versions/triggers | [listCallbackUrl](/rest/api/logic/workflowversions/listcallbackurl) |
355355
| Microsoft.MachineLearning/webServices | [listkeys](/rest/api/machinelearning/webservices/listkeys) |
356356
| Microsoft.MachineLearning/Workspaces | listworkspacekeys |
357-
| Microsoft.MachineLearningServices/workspaces/computes | [listKeys](/rest/api/azureml/2022-10-01/compute/list-keys) |
358-
| Microsoft.MachineLearningServices/workspaces/computes | [listNodes](/rest/api/azureml/2022-10-01/compute/list-nodes) |
359-
| Microsoft.MachineLearningServices/workspaces | [listKeys](/rest/api/azureml/2022-10-01/workspaces/list-keys) |
357+
| Microsoft.MachineLearningServices/workspaces/computes | [listKeys](/rest/api/azureml/2023-04-01/compute/list-keys) |
358+
| Microsoft.MachineLearningServices/workspaces/computes | [listNodes](/rest/api/azureml/2023-04-01/compute/list-nodes) |
359+
| Microsoft.MachineLearningServices/workspaces | [listKeys](/rest/api/azureml/2023-04-01/workspaces/list-keys) |
360360
| Microsoft.Maps/accounts | [listKeys](/rest/api/maps-management/accounts/listkeys) |
361361
| Microsoft.Media/mediaservices/assets | [listContainerSas](/rest/api/media/assets/listcontainersas) |
362362
| Microsoft.Media/mediaservices/assets | [listStreamingLocators](/rest/api/media/assets/liststreaminglocators) |
@@ -507,31 +507,33 @@ Returns an object representing a resource's runtime state.
507507

508508
Namespace: [az](bicep-functions.md#namespaces-for-functions).
509509

510-
The reference function is available in Bicep files, but typically you don't need it. Instead, use the symbolic name for the resource.
510+
The Bicep files provide access to the reference function, although it is typically unnecessary. Instead, it is recommended to use the symbolic name of the resource. The reference function can only be used within the `properties` object of a resource and cannot be employed for top-level properties like `name` or `location`. The same generally applies to references using the symbolic name. However, for properties such as `name`, it is possible to generate a template without utilizing the reference function. Sufficient information about the resource name is known to directly emit the name. It is referred to as compile-time properties. Bicep validation can identify any incorrect usage of the symbolic name.
511511

512-
The following example deploys a storage account. It uses the symbolic name `storageAccount` for the storage account to return a property.
512+
The following example deploys a storage account. The two outputs show the usage of both the reference function and the symbolic name.
513513

514514
```bicep
515-
param storageAccountName string
515+
param storageAccountName string = uniqueString(resourceGroup().id)
516+
param location string = resourceGroup().location
516517
517-
resource storageAccount 'Microsoft.Storage/storageAccounts@2019-06-01' = {
518+
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
518519
name: storageAccountName
519-
location: 'eastus'
520+
location: location
520521
kind: 'Storage'
521522
sku: {
522523
name: 'Standard_LRS'
523524
}
524525
}
525526
526-
output storageEndpoint object = storageAccount.properties.primaryEndpoints
527+
output storageEndpointReference object = reference(storageAccountName).primaryEndpoints
528+
output storageEndpointSymbolic object = storageAccount.properties.primaryEndpoints
527529
```
528530

529531
To get a property from an existing resource that isn't deployed in the template, use the `existing` keyword:
530532

531533
```bicep
532534
param storageAccountName string
533535
534-
resource storageAccount 'Microsoft.Storage/storageAccounts@2019-06-01' existing = {
536+
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' existing = {
535537
name: storageAccountName
536538
}
537539
@@ -563,10 +565,11 @@ For example:
563565

564566
```bicep
565567
param storageAccountName string
568+
param location string = resourceGroup().location
566569
567-
resource storageAccount 'Microsoft.Storage/storageAccounts@2019-06-01' = {
570+
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
568571
name: storageAccountName
569-
location: 'eastus'
572+
location: location
570573
kind: 'Storage'
571574
sku: {
572575
name: 'Standard_LRS'
@@ -581,7 +584,7 @@ To get the resource ID for a resource that isn't deployed in the Bicep file, use
581584
```bicep
582585
param storageAccountName string
583586
584-
resource storageAccount 'Microsoft.Storage/storageAccounts@2019-06-01' existing = {
587+
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' existing = {
585588
name: storageAccountName
586589
}
587590
@@ -638,7 +641,7 @@ var roleDefinitionId = {
638641
}
639642
}
640643
641-
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2018-09-01-preview' = {
644+
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
642645
name: guid(resourceGroup().id, principalId, roleDefinitionId[builtInRoleType].id)
643646
properties: {
644647
roleDefinitionId: roleDefinitionId[builtInRoleType].id
@@ -687,7 +690,7 @@ param allowedLocations array = [
687690
var mgScope = tenantResourceId('Microsoft.Management/managementGroups', targetMG)
688691
var policyDefinitionName = 'LocationRestriction'
689692
690-
resource policyDefinition 'Microsoft.Authorization/policyDefinitions@2020-03-01' = {
693+
resource policyDefinition 'Microsoft.Authorization/policyDefinitions@2021-06-01' = {
691694
name: policyDefinitionName
692695
properties: {
693696
policyType: 'Custom'
@@ -707,7 +710,7 @@ resource policyDefinition 'Microsoft.Authorization/policyDefinitions@2020-03-01'
707710
}
708711
}
709712
710-
resource location_lock 'Microsoft.Authorization/policyAssignments@2020-03-01' = {
713+
resource location_lock 'Microsoft.Authorization/policyAssignments@2021-06-01' = {
711714
name: 'location-lock'
712715
properties: {
713716
scope: mgScope
@@ -744,7 +747,7 @@ param policyDefinitionID string = '0a914e76-4921-4c19-b460-a2d36003525a'
744747
@description('Specifies the name of the policy assignment, can be used defined or an idempotent name as the defaultValue provides.')
745748
param policyAssignmentName string = guid(policyDefinitionID, resourceGroup().name)
746749
747-
resource policyAssignment 'Microsoft.Authorization/policyAssignments@2019-09-01' = {
750+
resource policyAssignment 'Microsoft.Authorization/policyAssignments@2022-06-01' = {
748751
name: policyAssignmentName
749752
properties: {
750753
scope: subscriptionResourceId('Microsoft.Resources/resourceGroups', resourceGroup().name)

0 commit comments

Comments
 (0)