Skip to content

Commit bb3b454

Browse files
committed
Re-open add copy() and copyIndex() function reference documentation
1 parent 06fafb9 commit bb3b454

File tree

3 files changed

+441
-1
lines changed

3 files changed

+441
-1
lines changed
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
---
2+
description: Reference for the 'copy' DSC configuration document resource loop
3+
ms.date: 02/28/2025
4+
ms.topic: reference
5+
title: copy
6+
---
7+
8+
# copy
9+
10+
## Synopsis
11+
12+
Defines a loop to create multiple instances of a resource.
13+
14+
## Syntax
15+
16+
```Syntax
17+
copy:
18+
name: <loopName>
19+
count: <numberOfIterations>
20+
```
21+
22+
## Description
23+
24+
The `copy` property enables you to create multiple instances of a resource in a
25+
DSC configuration. This is the equivalent implementation of the copy
26+
functionality from Azure Resource Manager (ARM) templates, but without support
27+
for variables and properties, which will be added in future releases.
28+
29+
When you use `copy` on a resource, DSC creates multiple instances of that
30+
resource based on the specified count. You can use the [`copyIndex()`][01]
31+
function within the resource definition to access the current iteration index
32+
and create unique names or property values for each instance.
33+
34+
> [!NOTE]
35+
> The `mode` and `batchSize` properties are not currently supported and will
36+
> result in an error if used.
37+
38+
## Examples
39+
40+
### Example 1 - Create multiple Echo resources
41+
42+
This example demonstrates the basic usage of `copy` to create three instances
43+
of a Debug Echo resource.
44+
45+
```yaml
46+
# copy.example.1.dsc.config.yaml
47+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
48+
resources:
49+
- name: "[format('Echo-{0}', copyIndex())]"
50+
copy:
51+
name: echoLoop
52+
count: 3
53+
type: Microsoft.DSC.Debug/Echo
54+
properties:
55+
output: "Hello DSC"
56+
```
57+
58+
```bash
59+
dsc config get --file copy.example.1.dsc.config.yaml
60+
```
61+
62+
```yaml
63+
results:
64+
- name: Echo-0
65+
type: Microsoft.DSC.Debug/Echo
66+
result:
67+
actualState:
68+
output: Hello DSC
69+
- name: Echo-1
70+
type: Microsoft.DSC.Debug/Echo
71+
result:
72+
actualState:
73+
output: Hello DSC
74+
- name: Echo-2
75+
type: Microsoft.DSC.Debug/Echo
76+
result:
77+
actualState:
78+
output: Hello DSC
79+
messages: []
80+
hadErrors: false
81+
```
82+
83+
### Example 2 - Using copyIndex with offset
84+
85+
This example demonstrates using [`copyIndex()`][01] with an offset to start
86+
numbering from a different value.
87+
88+
```yaml
89+
# copy.example.2.dsc.config.yaml
90+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
91+
resources:
92+
- name: "[format('Service-{0}', copyIndex(100))]"
93+
copy:
94+
name: serviceLoop
95+
count: 3
96+
type: Microsoft.DSC.Debug/Echo
97+
properties:
98+
output: "Service instance"
99+
```
100+
101+
```bash
102+
dsc config get --file copy.example.2.dsc.config.yaml
103+
```
104+
105+
```yaml
106+
results:
107+
- name: Service-100
108+
type: Microsoft.DSC.Debug/Echo
109+
result:
110+
actualState:
111+
output: Service instance
112+
- name: Service-101
113+
type: Microsoft.DSC.Debug/Echo
114+
result:
115+
actualState:
116+
output: Service instance
117+
- name: Service-102
118+
type: Microsoft.DSC.Debug/Echo
119+
result:
120+
actualState:
121+
output: Service instance
122+
messages: []
123+
hadErrors: false
124+
```
125+
126+
### Example 3 - Using named loop references
127+
128+
This example shows how to reference a specific loop by name when using
129+
[`copyIndex()`][01].
130+
131+
```yaml
132+
# copy.example.3.dsc.config.yaml
133+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
134+
resources:
135+
- name: "[format('Resource-{0}', copyIndex('mainLoop'))]"
136+
copy:
137+
name: mainLoop
138+
count: 2
139+
type: Microsoft.DSC.Debug/Echo
140+
properties:
141+
output: "From main loop"
142+
```
143+
144+
```bash
145+
dsc config get --file copy.example.3.dsc.config.yaml
146+
```
147+
148+
```yaml
149+
results:
150+
- name: Resource-0
151+
type: Microsoft.DSC.Debug/Echo
152+
result:
153+
actualState:
154+
output: From main loop
155+
- name: Resource-1
156+
type: Microsoft.DSC.Debug/Echo
157+
result:
158+
actualState:
159+
output: From main loop
160+
messages: []
161+
hadErrors: false
162+
```
163+
164+
## Properties
165+
166+
### name
167+
168+
The name of the copy loop. This name can be used with the [`copyIndex()`][01]
169+
function to reference the current iteration index of this specific loop.
170+
171+
```yaml
172+
Type: string
173+
Required: true
174+
```
175+
176+
### count
177+
178+
The number of iterations to perform. Must be a non-negative integer. If set to
179+
0, no instances of the resource are created.
180+
181+
```yaml
182+
Type: integer
183+
Required: true
184+
Minimum: 0
185+
```
186+
187+
### mode
188+
189+
> [!WARNING]
190+
> The `mode` property is not currently supported and will result in an error
191+
> if used.
192+
193+
This property is reserved for future implementation to specify whether resources
194+
should be created serially or in parallel.
195+
196+
### batchSize
197+
198+
> [!WARNING]
199+
> The `batchSize` property is not currently supported and will result in an
200+
> error if used.
201+
202+
This property is reserved for future implementation to specify how many
203+
resources to create in each batch when using parallel mode.
204+
205+
## Limitations
206+
207+
The current implementation has the following limitations:
208+
209+
- **Variables and properties**: Copy loops for variables and properties are not
210+
yet supported.
211+
- **Mode control**: The `mode` property (serial/parallel) is not implemented.
212+
- **Batch processing**: The `batchSize` property is not implemented.
213+
- **Name expressions**: The resource name expression must evaluate to a string.
214+
215+
## Related Functions
216+
217+
- [`copyIndex()`][01] - Returns the current iteration index of a copy loop.
218+
219+
<!-- Link reference definitions -->
220+
[01]: ./copyIndex.md

0 commit comments

Comments
 (0)