Skip to content

Commit 1b73f76

Browse files
committed
Add BCP139
1 parent 3815ca7 commit 1b73f76

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ If you need more information about a particular diagnostic code, select the **Fe
143143
| <a id='BCP136' />BCP136 | Error | Expected a loop item variable identifier at this location. |
144144
| <a id='BCP137' />BCP137 | Error | Loop expected an expression of type "{LanguageConstants.Array}" but the provided value is of type "{actualType}". |
145145
| <a id='BCP138' />BCP138 | Error | For-expressions aren't supported in this context. For-expressions may be used as values of resource, module, variable, and output declarations, or values of resource and module properties. |
146-
| <a id='BCP139' />BCP139 | Warning | 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. |
146+
| <a id='BCP083' />[BCP139](./diagnostics/bcp139.md) | Error | 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. |
147147
| <a id='BCP140' />BCP140 | Error | The multi-line string at this location isn't terminated. Terminate it with "'''. |
148148
| <a id='BCP141' />BCP141 | Error | The expression can't be used as a decorator as it isn't callable. |
149149
| <a id='BCP142' />BCP142 | Error | Property value for-expressions can't be nested. |
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
title: BCP139
3+
description: Error - 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.
4+
ms.topic: reference
5+
ms.custom: devx-track-bicep
6+
ms.date: 09/19/2024
7+
---
8+
9+
# Bicep error code - BCP139
10+
11+
This error occurs when you use [`resource`](../file.md#resources) to deploy resources to a different scope than the target one. You should use [`module`](../file.md#modules) instead. For more information, see the following articles depending on the scope:
12+
13+
- Resource group: [Scope to different resource group](../deploy-to-resource-group.md#scope-to-different-resource-group).
14+
- Subscription: [Deployment scopes](../deploy-to-subscription.md#deployment-scopes).
15+
- Management group: [Deployment scopes](../deploy-to-management-group.md#deployment-scopes).
16+
- Tenant: [Deployment scopes](../deploy-to-tenant.md#deployment-scopes).
17+
18+
## Error description
19+
20+
`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.`
21+
22+
## Solution
23+
24+
To deploy resources to a scope that isn't the target scope, add a `module`.
25+
26+
## Examples
27+
28+
The following example deploys a storage account resource to a different resource group in the same subscription. The example raises the error because the `module` declaration type isn't used:
29+
30+
```bicep
31+
param otherResourceGroup string
32+
param location string
33+
34+
resource storage 'Microsoft.Storage/storageAccounts@2023-05-01' = {
35+
name: uniqueString(resourceGroup().id)
36+
scope: resourceGroup(otherResourceGroup)
37+
location: location
38+
sku: {
39+
name: 'Standard_LRS'
40+
}
41+
kind: 'StorageV2'
42+
}
43+
```
44+
45+
You can fix the error by using the `module` declaration type:
46+
47+
```bicep
48+
param otherResourceGroup string
49+
50+
// module deployed to resource group in the same subscription
51+
module exampleModule 'module.bicep' = {
52+
name: 'deployStorageToAnotherRG'
53+
scope: resourceGroup(otherResourceGroup)
54+
}
55+
```
56+
57+
The following example deploys a resource group to a different subscription. The example raises the error because `module` isn't used
58+
59+
```bicep
60+
targetScope = 'subscription'
61+
62+
param otherSubscriptionID string
63+
64+
// module deployed at subscription level but in a different subscription
65+
resource exampleResource 'Microsoft.Resources/resourceGroups@2024-03-01' = {
66+
name: 'deployToDifferentSub'
67+
scope: subscription(otherSubscriptionID)
68+
location: 'eastus'
69+
}
70+
```
71+
72+
You can fix the error by using the `module` declaration type:
73+
74+
```bicep
75+
targetScope = 'subscription'
76+
77+
param otherSubscriptionID string
78+
79+
// module deployed at subscription level but in a different subscription
80+
module exampleModule 'module.bicep' = {
81+
name: 'deployToDifferentSub'
82+
scope: subscription(otherSubscriptionID)
83+
}
84+
```
85+
86+
## Next steps
87+
88+
For more information about Bicep error and warning codes, see [Bicep core diagnostics](../bicep-core-diagnostics.md).

articles/azure-resource-manager/bicep/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@
644644
href: diagnostics/bcp088.md
645645
- name: BCP089
646646
href: diagnostics/bcp089.md
647+
- name: BCP139
648+
href: diagnostics/bcp139.md
647649
- name: BCP192
648650
href: diagnostics/bcp192.md
649651
- name: BCP288

0 commit comments

Comments
 (0)