@@ -334,4 +334,112 @@ resources:
334334 $out.results [1 ].name | Should - Be ' Server-1'
335335 $out.results [1 ].result.actualState.output | Should - Be ' web-2'
336336 }
337+
338+ It ' Copy works with reference() to previous copy loop resource' {
339+ $configYaml = @'
340+ $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
341+ resources:
342+ - name: "[format('Policy-{0}', copyIndex())]"
343+ copy:
344+ name: policyLoop
345+ count: 2
346+ type: Microsoft.DSC.Debug/Echo
347+ properties:
348+ output: "[format('PolicyId-{0}', copyIndex())]"
349+ - name: "[format('Permission-{0}', copyIndex())]"
350+ copy:
351+ name: permissionLoop
352+ count: 2
353+ type: Microsoft.DSC.Debug/Echo
354+ properties:
355+ output: "[reference(resourceId('Microsoft.DSC.Debug/Echo', format('Policy-{0}', copyIndex()))).output]"
356+ dependsOn:
357+ - "[resourceId('Microsoft.DSC.Debug/Echo', format('Policy-{0}', copyIndex()))]"
358+ '@
359+ $out = dsc - l trace config get - i $configYaml 2> $testdrive / error.log | ConvertFrom-Json
360+ $LASTEXITCODE | Should - Be 0 - Because (Get-Content $testdrive / error.log - Raw | Out-String )
361+ $out.results.Count | Should - Be 4
362+ $out.results [0 ].name | Should - Be ' Policy-0'
363+ $out.results [0 ].result.actualState.output | Should - Be ' PolicyId-0'
364+ $out.results [1 ].name | Should - Be ' Policy-1'
365+ $out.results [1 ].result.actualState.output | Should - Be ' PolicyId-1'
366+ $out.results [2 ].name | Should - Be ' Permission-0'
367+ $out.results [2 ].result.actualState.output | Should - Be ' PolicyId-0'
368+ $out.results [3 ].name | Should - Be ' Permission-1'
369+ $out.results [3 ].result.actualState.output | Should - Be ' PolicyId-1'
370+ }
371+
372+ It ' Copy works with reference() accessing nested property from previous loop' {
373+ $configYaml = @'
374+ $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
375+ resources:
376+ - name: "[format('Source-{0}', copyIndex())]"
377+ copy:
378+ name: sourceLoop
379+ count: 2
380+ type: Microsoft.DSC.Debug/Echo
381+ properties:
382+ output: "[concat('Value-', string(copyIndex(100)))]"
383+ - name: "[format('Target-{0}', copyIndex())]"
384+ copy:
385+ name: targetLoop
386+ count: 2
387+ type: Microsoft.DSC.Debug/Echo
388+ properties:
389+ output: "[concat('Copied: ', reference(resourceId('Microsoft.DSC.Debug/Echo', format('Source-{0}', copyIndex()))).output)]"
390+ dependsOn:
391+ - "[resourceId('Microsoft.DSC.Debug/Echo', format('Source-{0}', copyIndex()))]"
392+ '@
393+ $out = dsc - l trace config get - i $configYaml 2> $testdrive / error.log | ConvertFrom-Json
394+ $LASTEXITCODE | Should - Be 0 - Because (Get-Content $testdrive / error.log - Raw | Out-String )
395+ $out.results.Count | Should - Be 4
396+ $out.results [0 ].name | Should - Be ' Source-0'
397+ $out.results [0 ].result.actualState.output | Should - Be ' Value-100'
398+ $out.results [1 ].name | Should - Be ' Source-1'
399+ $out.results [1 ].result.actualState.output | Should - Be ' Value-101'
400+ $out.results [2 ].name | Should - Be ' Target-0'
401+ $out.results [2 ].result.actualState.output | Should - Be ' Copied: Value-100'
402+ $out.results [3 ].name | Should - Be ' Target-1'
403+ $out.results [3 ].result.actualState.output | Should - Be ' Copied: Value-101'
404+ }
405+
406+ It ' Copy with multiple nested copyIndex() calls in reference()' {
407+ $configYaml = @'
408+ $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
409+ resources:
410+ - name: "[format('Primary-{0}', copyIndex())]"
411+ copy:
412+ name: primaryLoop
413+ count: 3
414+ type: Microsoft.DSC.Debug/Echo
415+ properties:
416+ output: "[format('Data-{0}', add(copyIndex(), 1000))]"
417+ - name: "[format('Secondary-{0}', copyIndex())]"
418+ copy:
419+ name: secondaryLoop
420+ count: 3
421+ type: Microsoft.DSC.Debug/Echo
422+ properties:
423+ output: "[format('From {0}: {1}', copyIndex(), reference(resourceId('Microsoft.DSC.Debug/Echo', format('Primary-{0}', copyIndex()))).output)]"
424+ dependsOn:
425+ - "[resourceId('Microsoft.DSC.Debug/Echo', format('Primary-{0}', copyIndex()))]"
426+ '@
427+ $out = dsc - l trace config get - i $configYaml 2> $testdrive / error.log | ConvertFrom-Json
428+ $LASTEXITCODE | Should - Be 0 - Because (Get-Content $testdrive / error.log - Raw | Out-String )
429+ $out.results.Count | Should - Be 6
430+ $out.results [0 ].name | Should - Be ' Primary-0'
431+ $out.results [0 ].result.actualState.output | Should - Be ' Data-1000'
432+ $out.results [1 ].name | Should - Be ' Primary-1'
433+ $out.results [1 ].result.actualState.output | Should - Be ' Data-1001'
434+ $out.results [2 ].name | Should - Be ' Primary-2'
435+ $out.results [2 ].result.actualState.output | Should - Be ' Data-1002'
436+ $out.results [3 ].name | Should - Be ' Secondary-0'
437+ $out.results [3 ].result.actualState.output | Should - Be ' From 0: Data-1000'
438+ $out.results [4 ].name | Should - Be ' Secondary-1'
439+ $out.results [4 ].result.actualState.output | Should - Be ' From 1: Data-1001'
440+ $out.results [5 ].name | Should - Be ' Secondary-2'
441+ $out.results [5 ].result.actualState.output | Should - Be ' From 2: Data-1002'
442+ }
443+
444+
337445}
0 commit comments