@@ -161,6 +161,56 @@ messages: []
161161hadErrors: false
162162` ` `
163163
164+ # ## Example 4 - Using expressions for count with parameters
165+
166+ This example demonstrates using an expression for the `count` property, which
167+ allows you to dynamically determine the number of resource instances to create
168+ based on a parameter value. This is commonly used to make configurations
169+ flexible and reusable.
170+
171+ ` ` ` yaml
172+ # copy.example.4.dsc.config.yaml
173+ $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
174+ parameters:
175+ instanceCount:
176+ type: int
177+ defaultValue: 2
178+ resources:
179+ - name: "[format('Dynamic-{0}', copyIndex())]"
180+ copy:
181+ name: dynamicLoop
182+ count: "[parameters('instanceCount')]"
183+ type: Microsoft.DSC.Debug/Echo
184+ properties:
185+ output: "[format('Instance {0} of {1}', copyIndex(), parameters('instanceCount'))]"
186+ ` ` `
187+
188+ ` ` ` bash
189+ dsc config get --file copy.example.4.dsc.config.yaml --parameters '{"instanceCount": 4}'
190+ ` ` `
191+
192+ ` ` ` yaml
193+ results:
194+ - metadata:
195+ Microsoft.DSC:
196+ duration: PT0.2173106S
197+ name: Dynamic-0
198+ type: Microsoft.DSC.Debug/Echo
199+ result:
200+ actualState:
201+ output: Instance 0 of 2
202+ - metadata:
203+ Microsoft.DSC:
204+ duration: PT0.0161486S
205+ name: Dynamic-1
206+ type: Microsoft.DSC.Debug/Echo
207+ result:
208+ actualState:
209+ output: Instance 1 of 2
210+ messages: []
211+ hadErrors: false
212+ ` ` `
213+
164214# # Properties
165215
166216# ## name
@@ -178,6 +228,11 @@ Required: true
178228The number of iterations to perform. Must be a non-negative integer. If set to
1792290, no instances of the resource are created.
180230
231+ The `count` property accepts both literal integer values and expressions that
232+ evaluate to an integer, such as parameter references using the
233+ [`parameters()`][02] function. This allows you to dynamically control the
234+ number of resource instances based on configuration parameters.
235+
181236` ` ` yaml
182237Type: integer
183238Required: true
@@ -215,6 +270,8 @@ The current implementation has the following limitations:
215270# # Related Functions
216271
217272- [`copyIndex()`][01] - Returns the current iteration index of a copy loop.
273+ - [`parameters()`][02] - Returns the value of a configuration parameter.
218274
219275<!-- Link reference definitions -->
220276[01] : ./copyIndex.md
277+ [02] : ./parameters.md
0 commit comments