Skip to content

Commit d0a107e

Browse files
authored
Merge pull request #283640 from mumian/0801-spread-intellisense
spread operator override
2 parents d0e564f + 077b915 commit d0a107e

File tree

3 files changed

+66
-31
lines changed

3 files changed

+66
-31
lines changed
Loading

articles/azure-resource-manager/bicep/operator-spread.md

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Bicep spread operator
33
description: Describes Bicep spread operator.
44
ms.topic: conceptual
55
ms.custom: devx-track-bicep
6-
ms.date: 05/21/2024
6+
ms.date: 08/07/2024
77
---
88

99
# Bicep spread operator
@@ -21,15 +21,15 @@ The spread operator is used to copy properties from one object to another or to
2121
The following example shows the spread operator used in an object:
2222

2323
```bicep
24-
var objA = { bar: 'bar' }
25-
output objB object = { foo: 'foo', ...objA }
24+
var objA = { color: 'white' }
25+
output objB object = { shape: 'circle', ...objA }
2626
```
2727

2828
Output from the example:
2929

3030
| Name | Type | Value |
3131
|------|------|-------|
32-
| `objB` | object | { foo: 'foo', bar: 'bar' } |
32+
| `objB` | object | { shape: 'circle', color: 'white' } |
3333

3434
The following example shows the spread operator used in an array:
3535

@@ -60,10 +60,10 @@ Output from the example:
6060
The following example shows spread used in a multi-line operation:
6161

6262
```bicep
63-
var objA = { foo: 'foo' }
64-
var objB = { bar: 'bar' }
65-
output combined object = {
66-
...objA
63+
var objA = { color: 'white' }
64+
var objB = { shape: 'circle'}
65+
output objCombined object = {
66+
...objA
6767
...objB
6868
}
6969
```
@@ -72,39 +72,70 @@ In this usage, comma isn't used between the two lines. Output from the example:
7272

7373
| Name | Type | Value |
7474
|------|------|-------|
75-
| `combined` | object | { foo: 'foo', bar: 'bar' } |
75+
| `objCombined` | object | { color: 'white', shape: 'circle' } |
7676

77-
The spread operation can be used to avoid setting an optional property. For example:
77+
The spread operation can be used to avoid setting an optional property. In the following example, _accessTier_ is set only if the parameter _tier_ isn't an empty string.
7878

7979
```bicep
80-
param vmImageResourceId string = ''
81-
82-
var bar = vmImageResourceId != '' ? {
83-
id: vmImageResourceId
84-
} : {}
85-
86-
output foo object = {
87-
...bar
88-
alwaysSet: 'value'
80+
param location string = resourceGroup().location
81+
param tier string = 'Hot'
82+
83+
var storageAccountName = uniqueString(resourceGroup().id)
84+
var accessTier = tier != '' ? {accessTier: tier} : {}
85+
86+
resource mystorage 'Microsoft.Storage/storageAccounts@2023-05-01' = {
87+
name: storageAccountName
88+
location: location
89+
sku: {
90+
name: 'Standard_LRS'
91+
}
92+
kind: 'StorageV2'
93+
properties: {
94+
...accessTier
95+
}
8996
}
9097
```
9198

92-
Output from the example:
99+
The preceding example can also be written as:
93100

94-
| Name | Type | Value |
95-
|------|------|-------|
96-
| `foo` | object | {"alwaysSet":"value"} |
101+
```bicep
102+
param location string = resourceGroup().location
103+
param tier string = 'Hot'
104+
105+
var storageAccountName = uniqueString(resourceGroup().id)
106+
107+
resource mystorage 'Microsoft.Storage/storageAccounts@2023-05-01' = {
108+
name: storageAccountName
109+
location: location
110+
sku: {
111+
name: 'Standard_LRS'
112+
}
113+
kind: 'StorageV2'
114+
properties: {
115+
...(tier != '' ? {accesssTier: tier} : {})
116+
}
117+
}
118+
```
97119

98-
The preceding example can also be written as:
120+
The spread operator can be used to override existing properties.
99121

100122
```bicep
101-
param vmImageResourceId string = ''
123+
param location string = resourceGroup().location
124+
param storageProperties {
125+
accessTier: string?
126+
}
102127
103-
output foo object = {
104-
...(vmImageResourceId != '' ? {
105-
id: vmImageResourceId
106-
} : {})
107-
alwaysSet: 'value'
128+
resource mystorage 'Microsoft.Storage/storageAccounts@2023-05-01' = {
129+
name: uniqueString(resourceGroup().id)
130+
location: location
131+
sku: {
132+
name: 'Standard_LRS'
133+
}
134+
kind: 'StorageV2'
135+
properties: {
136+
accessTier: 'Cold'
137+
...storageProperties
138+
}
108139
}
109140
```
110141

articles/azure-resource-manager/bicep/quickstart-create-bicep-use-visual-studio-code.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Create Bicep files - Visual Studio Code
33
description: Use Visual Studio Code and the Bicep extension to Bicep files for deploy Azure resources
4-
ms.date: 03/20/2024
4+
ms.date: 08/05/2024
55
ms.topic: quickstart
66
ms.custom: mode-ui, devx-track-bicep
77
#Customer intent: As a developer new to Azure deployment, I want to learn how to use Visual Studio Code to create and edit Bicep files, so I can use them to deploy Azure resources.
@@ -172,6 +172,10 @@ You're almost done. Just provide values for those properties.
172172

173173
Again, intellisense helps you. Set `name` to `storageAccountName`, which is the parameter that contains a name for the storage account. For `location`, set it to `location`, which is a parameter you created earlier. When adding `sku.name` and `kind`, intellisense presents the valid options.
174174

175+
To add optional properties alongside the required properties, place the cursor at the desired location and press <kbd>Ctrl</kbd>+<kbd>Space</kbd>. Intellisense suggests unused properties as shown in the following screenshot.
176+
177+
:::image type="content" source="./media/quickstart-create-bicep-use-visual-studio-code/bicep-visual-studio-code-add-properties.png" alt-text="Screenshot of adding additional properties.":::
178+
175179
When finished, you have:
176180

177181
```bicep

0 commit comments

Comments
 (0)