Skip to content

Commit 020fe42

Browse files
authored
Merge pull request #301870 from mumian/0625-bcp139
update the BCP139 samples
2 parents fc3f4a4 + 227f3f2 commit 020fe42

File tree

1 file changed

+28
-14
lines changed
  • articles/azure-resource-manager/bicep/diagnostics

1 file changed

+28
-14
lines changed

articles/azure-resource-manager/bicep/diagnostics/bcp139.md

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: BCP139
33
description: A resource's scope must match the scope of the Bicep file for it to be deployable. You must use modules to deploy resources to a different scope.
44
ms.topic: reference
55
ms.custom: devx-track-bicep
6-
ms.date: 02/12/2025
6+
ms.date: 06/25/2025
77
---
88

99
# Bicep diagnostic code - BCP139
@@ -32,13 +32,14 @@ To deploy resources to a scope that isn't the target scope, add a `module`.
3232
The following example deploys a storage account resource to a different resource group in the same subscription. The example raises the diagnostic because the `module` declaration type isn't used:
3333

3434
```bicep
35-
param otherResourceGroup string
35+
param targetResourceGroup string
36+
param storageAccountName string
3637
param location string
3738
3839
// resource deployed to a different resource group in the same subscription
3940
resource storage 'Microsoft.Storage/storageAccounts@2023-05-01' = {
40-
name: uniqueString(resourceGroup().id)
41-
scope: resourceGroup(otherResourceGroup)
41+
name: storageAccountName
42+
scope: resourceGroup(targetResourceGroup)
4243
location: location
4344
sku: {
4445
name: 'Standard_LRS'
@@ -50,12 +51,17 @@ resource storage 'Microsoft.Storage/storageAccounts@2023-05-01' = {
5051
You can fix the diagnostic by using the `module` declaration type:
5152

5253
```bicep
53-
param otherResourceGroup string
54-
55-
// module deployed to a different resource group in the same subscription
56-
module exampleModule 'module.bicep' = {
57-
name: 'deployStorageToAnotherRG'
58-
scope: resourceGroup(otherResourceGroup)
54+
param targetResourceGroup string
55+
param storageAccountName string = uniqueString(resourceGroup().id)
56+
param location string = 'eastus'
57+
58+
module storageModule './module.bicep' = {
59+
name: 'deployStorage'
60+
scope: resourceGroup(targetResourceGroup)
61+
params: {
62+
storageAccountName: storageAccountName
63+
location: location
64+
}
5965
}
6066
```
6167

@@ -64,13 +70,15 @@ The following example deploys a resource group to a different subscription. The
6470
```bicep
6571
targetScope = 'subscription'
6672
67-
param otherSubscriptionID string
73+
param targetSubscriptionID string
74+
param resourceGroupName string
75+
param location string
6876
6977
// resource deployed to a different subscription
7078
resource exampleResource 'Microsoft.Resources/resourceGroups@2024-03-01' = {
71-
name: 'deployToDifferentSub'
72-
scope: subscription(otherSubscriptionID)
73-
location: 'eastus'
79+
name: resourceGroupName
80+
scope: subscription(targetSubscriptionID)
81+
location: location
7482
}
7583
```
7684

@@ -80,11 +88,17 @@ You can fix the diagnostic by using the `module` declaration type:
8088
targetScope = 'subscription'
8189
8290
param otherSubscriptionID string
91+
param resourceGroupName string
92+
param location string
8393
8494
// module deployed to a different subscription
8595
module exampleModule 'module.bicep' = {
8696
name: 'deployToDifferentSub'
8797
scope: subscription(otherSubscriptionID)
98+
params: {
99+
resourceGroupName: resourceGroupName
100+
location: location
101+
}
88102
}
89103
```
90104

0 commit comments

Comments
 (0)