Skip to content

Commit 97ba9cb

Browse files
authored
Merge pull request #1430 from SteveL-MSFT/deprecate-copy
Add deprecation message to use of `copy`
2 parents 608339e + 9c29e3b commit 97ba9cb

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

dsc/tests/dsc_copy.tests.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,4 +440,24 @@ resources:
440440
$out.results[5].name | Should -Be 'Secondary-2'
441441
$out.results[5].result.actualState.output | Should -Be 'From 2: Data-1002'
442442
}
443+
444+
It 'Use of copy emits a deprecation warning' {
445+
$configYaml = @'
446+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
447+
resources:
448+
- name: "[format('Test-{0}', copyIndex())]"
449+
copy:
450+
name: testLoop
451+
count: 1
452+
type: Microsoft.DSC.Debug/Echo
453+
properties:
454+
output: Hello
455+
'@
456+
$out = dsc -l trace config get -i $configYaml 2>$testdrive/error.log | ConvertFrom-Json
457+
$LASTEXITCODE | Should -Be 0 -Because ((Get-Content $testdrive/error.log) | Out-String)
458+
$out.results.Count | Should -Be 1
459+
$out.results[0].name | Should -Be 'Test-0'
460+
$out.results[0].result.actualState.output | Should -Be 'Hello'
461+
(Get-Content $testdrive/error.log -Raw) | Should -BeLike "*WARN*Copy for loop 'testLoop' is deprecated and will be removed in a future release. See https://github.com/PowerShell/DSC/issues/1429 for more details.*"
462+
}
443463
}

lib/dsc-lib/locales/en-us.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ metadataRefreshEnvFound = "Resource returned '_refreshEnv' which indicates envir
9494
metadataRefreshEnvOnlyAffectsSet = "Resource returned '_refreshEnv' which indicates environment variable refresh is needed but current operation is '%{operation}' which is not 'set', so ignoring"
9595
metadataRefreshEnvNoOperationContext = "Resource returned '_refreshEnv' which indicates environment variable refresh is needed but no operation context is available"
9696
metadataRefreshEnvNoContext = "Resource returned '_refreshEnv' which indicates environment variable refresh is needed but no context is available"
97+
copyDeprecated = "Copy for loop '%{name}' is deprecated and will be removed in a future release. See https://github.com/PowerShell/DSC/issues/1429 for more details."
9798

9899
[configure.parameters]
99100
importingParametersFromComplexInput = "Importing parameters from complex input"

lib/dsc-lib/src/configure/depends_on.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::types::FullyQualifiedTypeName;
1010
use rust_i18n::t;
1111
use serde_json::{Map, Value};
1212
use super::context::Context;
13-
use tracing::debug;
13+
use tracing::{debug, warn};
1414

1515
/// Gets the invocation order of resources based on their dependencies
1616
///
@@ -141,6 +141,7 @@ fn unroll_and_push(order: &mut Vec<Resource>, resource: &Resource, parser: &mut
141141
// if the resource contains `Copy`, unroll it
142142
if let Some(copy) = &resource.copy {
143143
debug!("{}", t!("configure.mod.unrollingCopy", name = &copy.name, count = copy.count));
144+
warn!("{}", t!("configure.mod.copyDeprecated", name = &copy.name));
144145
context.process_mode = ProcessMode::Copy;
145146
context.copy_current_loop_name.clone_from(&copy.name);
146147
let mut copy_resources = Vec::<Resource>::new();
@@ -214,7 +215,7 @@ fn unroll_and_push(order: &mut Vec<Resource>, resource: &Resource, parser: &mut
214215
other: Map::new(),
215216
}
216217
});
217-
218+
218219
let mut microsoft = metadata.microsoft.clone().unwrap_or_default();
219220
let mut copy_loops = microsoft.copy_loops.clone().unwrap_or_default();
220221
copy_loops.insert(copy.name.clone(), Value::Number(i.into()));

0 commit comments

Comments
 (0)