-
Notifications
You must be signed in to change notification settings - Fork 54
Reopen add copy() and copyIndex() function reference documentation
#1147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SteveL-MSFT
merged 13 commits into
PowerShell:main
from
Gijsreyn:gh-57/main/add-copy-function
Oct 28, 2025
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
bb3b454
Re-open add `copy()` and `copyIndex()` function reference documentation
Gijsreyn 70bcdbe
Line break
Gijsreyn 1d955b1
Re-open add `copy()` and `copyIndex()` function reference documentation
Gijsreyn 490d687
Line break
Gijsreyn f416602
Merge branch 'gh-57/main/add-copy-function' of https://github.com/Gij…
Gijsreyn 0488cb8
Fix formatting
Gijsreyn bf28ccb
Re-open add `copy()` and `copyIndex()` function reference documentation
Gijsreyn 21a83e5
Line break
Gijsreyn b91d21f
Re-open add `copy()` and `copyIndex()` function reference documentation
Gijsreyn e80081f
Line break
Gijsreyn cc08525
Fix formatting
Gijsreyn 1c45a47
Add new example
Gijsreyn cbae165
Merge branch 'gh-57/main/add-copy-function' of https://github.com/Gij…
Gijsreyn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| --- | ||
| description: Reference for the 'copy' DSC configuration document resource loop | ||
| ms.date: 02/28/2025 | ||
| ms.topic: reference | ||
| title: copy | ||
| --- | ||
|
|
||
| # copy | ||
|
|
||
| ## Synopsis | ||
|
|
||
| Defines a loop to create multiple instances of a resource. | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```Syntax | ||
| copy: | ||
| name: <loopName> | ||
| count: <numberOfIterations> | ||
| ``` | ||
|
|
||
| ## Description | ||
|
|
||
| The `copy` property enables you to create multiple instances of a resource in a | ||
| DSC configuration. This is the equivalent implementation of the copy | ||
| functionality from Azure Resource Manager (ARM) templates, but without support | ||
| for variables and properties, which will be added in future releases. | ||
|
|
||
| When you use `copy` on a resource, DSC creates multiple instances of that | ||
| resource based on the specified count. You can use the [`copyIndex()`][01] | ||
| function within the resource definition to access the current iteration index | ||
| and create unique names or property values for each instance. | ||
|
|
||
| > [!NOTE] | ||
| > The `mode` and `batchSize` properties are not currently supported and will | ||
| > result in an error if used. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Example 1 - Create multiple Echo resources | ||
|
|
||
| This example demonstrates the basic usage of `copy` to create three instances | ||
| of a Debug Echo resource. | ||
|
|
||
| ```yaml | ||
| # copy.example.1.dsc.config.yaml | ||
| $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
| resources: | ||
| - name: "[format('Echo-{0}', copyIndex())]" | ||
| copy: | ||
| name: echoLoop | ||
| count: 3 | ||
| type: Microsoft.DSC.Debug/Echo | ||
| properties: | ||
| output: "Hello DSC" | ||
| ``` | ||
|
|
||
| ```bash | ||
| dsc config get --file copy.example.1.dsc.config.yaml | ||
| ``` | ||
|
|
||
| ```yaml | ||
| results: | ||
| - name: Echo-0 | ||
| type: Microsoft.DSC.Debug/Echo | ||
| result: | ||
| actualState: | ||
| output: Hello DSC | ||
| - name: Echo-1 | ||
| type: Microsoft.DSC.Debug/Echo | ||
| result: | ||
| actualState: | ||
| output: Hello DSC | ||
| - name: Echo-2 | ||
| type: Microsoft.DSC.Debug/Echo | ||
| result: | ||
| actualState: | ||
| output: Hello DSC | ||
| messages: [] | ||
| hadErrors: false | ||
| ``` | ||
|
|
||
| ### Example 2 - Using copyIndex with offset | ||
|
|
||
| This example demonstrates using [`copyIndex()`][01] with an offset to start | ||
| numbering from a different value. | ||
|
|
||
| ```yaml | ||
| # copy.example.2.dsc.config.yaml | ||
| $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
| resources: | ||
| - name: "[format('Service-{0}', copyIndex(100))]" | ||
| copy: | ||
| name: serviceLoop | ||
| count: 3 | ||
| type: Microsoft.DSC.Debug/Echo | ||
| properties: | ||
| output: "Service instance" | ||
| ``` | ||
|
|
||
| ```bash | ||
| dsc config get --file copy.example.2.dsc.config.yaml | ||
| ``` | ||
|
|
||
| ```yaml | ||
| results: | ||
| - name: Service-100 | ||
| type: Microsoft.DSC.Debug/Echo | ||
| result: | ||
| actualState: | ||
| output: Service instance | ||
| - name: Service-101 | ||
| type: Microsoft.DSC.Debug/Echo | ||
| result: | ||
| actualState: | ||
| output: Service instance | ||
| - name: Service-102 | ||
| type: Microsoft.DSC.Debug/Echo | ||
| result: | ||
| actualState: | ||
| output: Service instance | ||
| messages: [] | ||
| hadErrors: false | ||
| ``` | ||
|
|
||
| ### Example 3 - Using named loop references | ||
|
|
||
| This example shows how to reference a specific loop by name when using | ||
| [`copyIndex()`][01]. | ||
|
|
||
| ```yaml | ||
| # copy.example.3.dsc.config.yaml | ||
| $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
| resources: | ||
| - name: "[format('Resource-{0}', copyIndex('mainLoop'))]" | ||
| copy: | ||
| name: mainLoop | ||
| count: 2 | ||
| type: Microsoft.DSC.Debug/Echo | ||
| properties: | ||
| output: "From main loop" | ||
| ``` | ||
|
|
||
| ```bash | ||
| dsc config get --file copy.example.3.dsc.config.yaml | ||
| ``` | ||
|
|
||
| ```yaml | ||
| results: | ||
| - name: Resource-0 | ||
| type: Microsoft.DSC.Debug/Echo | ||
| result: | ||
| actualState: | ||
| output: From main loop | ||
| - name: Resource-1 | ||
| type: Microsoft.DSC.Debug/Echo | ||
| result: | ||
| actualState: | ||
| output: From main loop | ||
| messages: [] | ||
| hadErrors: false | ||
| ``` | ||
|
|
||
| ## Properties | ||
|
|
||
| ### name | ||
|
|
||
| The name of the copy loop. This name can be used with the [`copyIndex()`][01] | ||
| function to reference the current iteration index of this specific loop. | ||
|
|
||
| ```yaml | ||
| Type: string | ||
| Required: true | ||
| ``` | ||
|
|
||
| ### count | ||
|
|
||
| The number of iterations to perform. Must be a non-negative integer. If set to | ||
| 0, no instances of the resource are created. | ||
|
|
||
| ```yaml | ||
| Type: integer | ||
| Required: true | ||
| Minimum: 0 | ||
| ``` | ||
|
|
||
| ### mode | ||
|
|
||
| > [!WARNING] | ||
| > The `mode` property is not currently supported and will result in an error | ||
| > if used. | ||
|
|
||
| This property is reserved for future implementation to specify whether resources | ||
| should be created serially or in parallel. | ||
|
|
||
| ### batchSize | ||
|
|
||
| > [!WARNING] | ||
| > The `batchSize` property is not currently supported and will result in an | ||
| > error if used. | ||
|
|
||
| This property is reserved for future implementation to specify how many | ||
| resources to create in each batch when using parallel mode. | ||
|
|
||
| ## Limitations | ||
|
|
||
| The current implementation has the following limitations: | ||
|
|
||
| - **Variables and properties**: Copy loops for variables and properties are not | ||
| yet supported. | ||
| - **Mode control**: The `mode` property (serial/parallel) is not implemented. | ||
| - **Batch processing**: The `batchSize` property is not implemented. | ||
| - **Name expressions**: The resource name expression must evaluate to a string. | ||
|
|
||
| ## Related Functions | ||
|
|
||
| - [`copyIndex()`][01] - Returns the current iteration index of a copy loop. | ||
|
|
||
| <!-- Link reference definitions --> | ||
| [01]: ./copyIndex.md | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.