Skip to content

Commit b9fc658

Browse files
authored
Merge pull request #307308 from mumian/1023-onlyifnotexist
Document the onlyIfNotExist decorator
2 parents e5f8de4 + b426734 commit b9fc658

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Declare resources in Bicep
33
description: Describes how to declare resources to deploy in Bicep.
44
ms.topic: conceptual
55
ms.custom: devx-track-bicep
6-
ms.date: 04/28/2025
6+
ms.date: 10/24/2025
77
---
88

99
# Resource declaration in Bicep
@@ -68,6 +68,7 @@ Decorators are written in the format `@expression` and are placed above resource
6868
| --------- | ----------- | ------- |
6969
| [batchSize](./bicep-import.md#export-variables-types-and-functions) | none | Set up instances to deploy sequentially. |
7070
| [description](#description) | string | Provide descriptions for the resource. |
71+
| [onlyIfNotExists](#onlyifnotexists) | none | Deploy the resource only if it doesn't already exist in the target scope. |
7172

7273
Decorators are in the [sys namespace](bicep-functions.md#namespaces-for-functions). If you need to differentiate a decorator from another item with the same name, preface the decorator with `sys`. For example, if your Bicep file includes a parameter named `description`, you must add the sys namespace when using the **description** decorator.
7374

@@ -99,6 +100,24 @@ resource storageAccountResources 'Microsoft.Storage/storageAccounts@2024-01-01'
99100

100101
Markdown-formatted text can be used for the description text.
101102

103+
### onlyIfNotExists
104+
105+
By default, when a Bicep deployment runs, Azure Resource Manager (ARM) creates the resource if it doesn’t exist or updates it if it does. If an existing resource has properties that differ from your template, ARM might attempt to update it—or fail if updates aren’t permitted.
106+
107+
Starting with Bicep version v0.38.3, the `@onlyIfNotExists()` decorator instructs ARM to create the resource only if it does not already exist. If a resource with the resource ID is found, ARM skips creation and leaves the existing resource unchanged.
108+
109+
```bicep
110+
@onlyIfNotExists()
111+
resource example 'Microsoft.Storage/storageAccounts@2025-01-01' = {
112+
name: 'mystorageacct'
113+
location: resourceGroup().location
114+
kind: 'StorageV2'
115+
sku: {
116+
name: 'Standard_LRS'
117+
}
118+
}
119+
```
120+
102121
## Resource name
103122

104123
Each resource has a name. When setting the resource name, pay attention to the [rules and restrictions for resource names](../management/resource-name-rules.md).

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ items:
267267
href: variables.md
268268
displayName: configuration
269269
- name: Resources (resource)
270+
displayName: batchsize,onlyifnotexists,description,decorators
270271
href: resource-declaration.md
271272
- name: Outputs (output)
272273
href: outputs.md

0 commit comments

Comments
 (0)