Skip to content

Commit 055f957

Browse files
authored
Merge pull request #287035 from mumian/0918-bcp139
Add BCP139
2 parents f458201 + bce3707 commit 055f957

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
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. |
@@ -171,7 +171,7 @@ If you need more information about a particular diagnostic code, select the **Fe
171171
| <a id='BCP167' />BCP167 | Error | Expected the "{" character or the "if" keyword at this location. |
172172
| <a id='BCP168' />BCP168 | Error | Length must not be a negative value. |
173173
| <a id='BCP169' />BCP169 | Error | Expected resource name to contain {expectedSlashCount} "/" character(s). The number of name segments must match the number of segments in the resource type. |
174-
| <a id='BCP170' />BCP170 | Error | Expected resource name to not contain any "/" characters. Child resources with a parent resource reference (via the parent property or via nesting) must not contain a fully-qualified name. |
174+
| <a id='BCP170' />BCP170 | Error | Expected resource name to not contain any "/" characters. Child resources with a parent resource reference (via the parent property or via nesting) must not contain a fully qualified name. |
175175
| <a id='BCP171' />BCP171 | Error | Resource type "{resourceType}" isn't a valid child resource of parent "{parentResourceType}". |
176176
| <a id='BCP172' />BCP172 | Error | The resource type can't be validated due to an error in parent resource "{resourceName}". |
177177
| <a id='BCP173' />BCP173 | Error | The property "{property}" can't be used in an existing resource declaration. |
@@ -258,7 +258,7 @@ If you need more information about a particular diagnostic code, select the **Fe
258258
| <a id='BCP261' />BCP261 | Error | A using declaration must be present in this parameters file. |
259259
| <a id='BCP262' />BCP262 | Error | More than one using declaration is present. |
260260
| <a id='BCP263' />BCP263 | Error | The file specified in the using declaration path doesn't exist. |
261-
| <a id='BCP264' />BCP264 | Error | Resource type "{resourceTypeName}" is declared in multiple imported namespaces ({ToQuotedStringWithCaseInsensitiveOrdering(namespaces)}), and must be fully-qualified. |
261+
| <a id='BCP264' />BCP264 | Error | Resource type "{resourceTypeName}" is declared in multiple imported namespaces ({ToQuotedStringWithCaseInsensitiveOrdering(namespaces)}), and must be fully qualified. |
262262
| <a id='BCP265' />BCP265 | Error | The name "{name}" isn't a function. Did you mean "{knownFunctionNamespace}.{knownFunctionName}"? |
263263
| <a id='BCP266' />BCP266 | Error | Expected a metadata identifier at this location. |
264264
| <a id='BCP267' />BCP267 | Error | Expected a metadata declaration after the decorator. |
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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/20/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 based 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 deployed to a different resource group in the same subscription
35+
resource storage 'Microsoft.Storage/storageAccounts@2023-05-01' = {
36+
name: uniqueString(resourceGroup().id)
37+
scope: resourceGroup(otherResourceGroup)
38+
location: location
39+
sku: {
40+
name: 'Standard_LRS'
41+
}
42+
kind: 'StorageV2'
43+
}
44+
```
45+
46+
You can fix the error by using the `module` declaration type:
47+
48+
```bicep
49+
param otherResourceGroup string
50+
51+
// module deployed to a different resource group in the same subscription
52+
module exampleModule 'module.bicep' = {
53+
name: 'deployStorageToAnotherRG'
54+
scope: resourceGroup(otherResourceGroup)
55+
}
56+
```
57+
58+
The following example deploys a resource group to a different subscription. The example raises the error because `module` isn't used
59+
60+
```bicep
61+
targetScope = 'subscription'
62+
63+
param otherSubscriptionID string
64+
65+
// resource deployed to a different subscription
66+
resource exampleResource 'Microsoft.Resources/resourceGroups@2024-03-01' = {
67+
name: 'deployToDifferentSub'
68+
scope: subscription(otherSubscriptionID)
69+
location: 'eastus'
70+
}
71+
```
72+
73+
You can fix the error by using the `module` declaration type:
74+
75+
```bicep
76+
targetScope = 'subscription'
77+
78+
param otherSubscriptionID string
79+
80+
// module deployed to a different subscription
81+
module exampleModule 'module.bicep' = {
82+
name: 'deployToDifferentSub'
83+
scope: subscription(otherSubscriptionID)
84+
}
85+
```
86+
87+
## Next steps
88+
89+
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
@@ -647,6 +647,8 @@
647647
href: diagnostics/bcp088.md
648648
- name: BCP089
649649
href: diagnostics/bcp089.md
650+
- name: BCP139
651+
href: diagnostics/bcp139.md
650652
- name: BCP192
651653
href: diagnostics/bcp192.md
652654
- name: BCP288

0 commit comments

Comments
 (0)