Skip to content

Commit 5e7b4a2

Browse files
authored
Merge pull request #1282 from SteveL-MSFT/bicep-param
Add support for ARM params file and Bicep params file formats
2 parents 83858bc + cd82644 commit 5e7b4a2

25 files changed

+257
-83
lines changed

dsc/examples/hello_world.dsc.bicep

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
targetScope = 'desiredStateConfiguration'
44

5+
param text string = 'Hello, world!'
6+
57
// use workaround where Bicep currently requires version in date format
68
resource echo 'Microsoft.DSC.Debug/Echo@2025-08-27' = {
79
name: 'exampleEcho'
810
properties: {
9-
output: 'Hello, world!'
11+
output: text
1012
}
1113
}
1214

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using 'hello_world.dsc.bicep'
2+
3+
param text = 'This is a parameterized hello world!'

dsc/locales/en-us.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ mcpAbout = "Use DSC as a MCP server"
4040
[main]
4141
ctrlCReceived = "Ctrl-C received"
4242
failedCtrlCHandler = "Failed to set Ctrl-C handler"
43-
failedReadingParametersFile = "Failed to read parameters file"
44-
readingParametersFromStdin = "Reading parameters from STDIN"
4543
generatingCompleter = "Generating completion script for"
46-
readingParametersFile = "Reading parameters from file"
4744
mergingParameters = "Merging inline parameters with parameters file (inline takes precedence)"
4845
failedMergingParameters = "Failed to merge parameters"
4946
usingDscVersion = "Running DSC version"

dsc/src/main.rs

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
use args::{Args, SubCommand};
55
use clap::{CommandFactory, Parser};
66
use clap_complete::generate;
7+
use dsc_lib::progress::ProgressFormat;
78
use mcp::start_mcp_server;
89
use rust_i18n::{i18n, t};
9-
use std::{io, io::Read, process::exit};
10+
use std::{io, process::exit};
1011
use sysinfo::{Process, RefreshKind, System, get_current_pid, ProcessRefreshKind};
1112
use tracing::{error, info, warn, debug};
12-
use dsc_lib::progress::ProgressFormat;
1313

14-
use crate::util::EXIT_INVALID_INPUT;
14+
use crate::util::{EXIT_INVALID_INPUT, get_input};
1515

1616
#[cfg(debug_assertions)]
1717
use crossterm::event;
@@ -54,38 +54,11 @@ fn main() {
5454
generate(shell, &mut cmd, "dsc", &mut io::stdout());
5555
},
5656
SubCommand::Config { subcommand, parameters, parameters_file, system_root, as_group, as_assert, as_include } => {
57-
// Read parameters from file if provided
58-
let file_params = if let Some(file_name) = &parameters_file {
59-
if file_name == "-" {
60-
info!("{}", t!("main.readingParametersFromStdin"));
61-
let mut stdin = Vec::<u8>::new();
62-
match io::stdin().read_to_end(&mut stdin) {
63-
Ok(_) => {
64-
match String::from_utf8(stdin) {
65-
Ok(input) => Some(input),
66-
Err(err) => {
67-
error!("{}: {err}", t!("util.invalidUtf8"));
68-
exit(EXIT_INVALID_INPUT);
69-
}
70-
}
71-
},
72-
Err(err) => {
73-
error!("{}: {err}", t!("util.failedToReadStdin"));
74-
exit(EXIT_INVALID_INPUT);
75-
}
76-
}
77-
} else {
78-
info!("{}: {file_name}", t!("main.readingParametersFile"));
79-
match std::fs::read_to_string(file_name) {
80-
Ok(content) => Some(content),
81-
Err(err) => {
82-
error!("{} '{file_name}': {err}", t!("main.failedReadingParametersFile"));
83-
exit(util::EXIT_INVALID_INPUT);
84-
}
85-
}
86-
}
87-
} else {
57+
let params = get_input(None, parameters_file.as_ref());
58+
let file_params = if params.is_empty() {
8859
None
60+
} else {
61+
Some(params)
8962
};
9063

9164
let merged_parameters = match (file_params, parameters) {

dsc/src/subcommand.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ fn list_extensions(dsc: &mut DscManager, extension_name: Option<&String>, format
607607
let capability_types = [
608608
(ExtensionCapability::Discover, "d"),
609609
(ExtensionCapability::Secret, "s"),
610+
(ExtensionCapability::Import, "i"),
610611
];
611612
let mut capabilities = "-".repeat(capability_types.len());
612613

dsc/tests/dsc_expressions.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Describe 'Expressions tests' {
7373
"@
7474
$out = dsc config get -i $yaml 2>&1
7575
$LASTEXITCODE | Should -Be 2
76-
$out | Should -BeLike "*ERROR*"
76+
,$out | Should -BeLike "*ERROR*" -Because ($out | Out-String)
7777
}
7878

7979
It 'Multi-line string literals work' {

dsc/tests/dsc_extension_discover.tests.ps1

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,37 @@ Describe 'Discover extension tests' {
2424
$out = dsc extension list | ConvertFrom-Json
2525
$LASTEXITCODE | Should -Be 0
2626
if ($IsWindows) {
27-
$out.Count | Should -Be 3 -Because ($out | Out-String)
27+
$out.Count | Should -Be 4 -Because ($out | Out-String)
2828
$out[0].type | Should -Be 'Microsoft.DSC.Extension/Bicep'
2929
$out[0].version | Should -Be '0.1.0'
3030
$out[0].capabilities | Should -BeExactly @('import')
3131
$out[0].manifest | Should -Not -BeNullOrEmpty
32-
$out[1].type | Should -Be 'Microsoft.Windows.Appx/Discover'
33-
$out[1].version | Should -Be '0.1.0'
34-
$out[1].capabilities | Should -BeExactly @('discover')
32+
$out[1].type | Should -BeExactly 'Microsoft.DSC.Extension/BicepParameters'
33+
$out[1].version | Should -BeExactly '0.1.0'
34+
$out[1].capabilities | Should -BeExactly @('import')
3535
$out[1].manifest | Should -Not -BeNullOrEmpty
36-
$out[2].type | Should -BeExactly 'Test/Discover'
37-
$out[2].version | Should -BeExactly '0.1.0'
36+
$out[2].type | Should -Be 'Microsoft.Windows.Appx/Discover'
37+
$out[2].version | Should -Be '0.1.0'
3838
$out[2].capabilities | Should -BeExactly @('discover')
3939
$out[2].manifest | Should -Not -BeNullOrEmpty
40+
$out[3].type | Should -BeExactly 'Test/Discover'
41+
$out[3].version | Should -BeExactly '0.1.0'
42+
$out[3].capabilities | Should -BeExactly @('discover')
43+
$out[3].manifest | Should -Not -BeNullOrEmpty
4044
} else {
41-
$out.Count | Should -Be 2 -Because ($out | Out-String)
45+
$out.Count | Should -Be 3 -Because ($out | Out-String)
4246
$out[0].type | Should -Be 'Microsoft.DSC.Extension/Bicep'
4347
$out[0].version | Should -Be '0.1.0'
4448
$out[0].capabilities | Should -BeExactly @('import')
4549
$out[0].manifest | Should -Not -BeNullOrEmpty
46-
$out[1].type | Should -BeExactly 'Test/Discover'
50+
$out[1].type | Should -BeExactly 'Microsoft.DSC.Extension/BicepParameters'
4751
$out[1].version | Should -BeExactly '0.1.0'
48-
$out[1].capabilities | Should -BeExactly @('discover')
52+
$out[1].capabilities | Should -BeExactly @('import')
4953
$out[1].manifest | Should -Not -BeNullOrEmpty
54+
$out[2].type | Should -BeExactly 'Test/Discover'
55+
$out[2].version | Should -BeExactly '0.1.0'
56+
$out[2].capabilities | Should -BeExactly @('discover')
57+
$out[2].manifest | Should -Not -BeNullOrEmpty
5058
}
5159
}
5260

dsc/tests/dsc_parameters.tests.ps1

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,65 @@ Describe 'Parameters tests' {
394394
$errorMessage | Should -BeLike "*ERROR*Empty input provided*"
395395
}
396396

397+
It 'Parameters in ARM syntax are supported' {
398+
$config_yaml = @"
399+
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
400+
parameters:
401+
myString:
402+
type: string
403+
myObject:
404+
type: object
405+
myArray:
406+
type: array
407+
myInt:
408+
type: int
409+
myBool:
410+
type: bool
411+
resources:
412+
- name: echo
413+
type: Microsoft.DSC.Debug/Echo
414+
properties:
415+
output: >-
416+
[concat(
417+
parameters('myString'),
418+
'-',
419+
parameters('myObject').prop1,
420+
'-',
421+
parameters('myArray')[0],
422+
parameters('myArray')[1],
423+
'-',
424+
string(parameters('myInt')),
425+
'-',
426+
string(parameters('myBool')
427+
)]
428+
"@
429+
$params = @{
430+
parameters = @{
431+
myString = @{
432+
value = 'Hello'
433+
}
434+
myObject = @{
435+
value = @{
436+
prop1 = 'World'
437+
}
438+
}
439+
myArray = @{
440+
value = @('Item1', 'Item2')
441+
}
442+
myInt = @{
443+
value = 123
444+
}
445+
myBool = @{
446+
value = $true
447+
}
448+
}
449+
} | ConvertTo-Json -Compress -Depth 5
450+
451+
$out = $config_yaml | dsc -l trace config -p $params get -f - 2> $TestDrive/error.log | ConvertFrom-Json
452+
$LASTEXITCODE | Should -Be 0 -Because (Get-Content -Path $TestDrive/error.log -Raw | Out-String)
453+
$out.results[0].result.actualState.output | Should -BeExactly 'Hello-World-Item1Item2-123-true'
454+
}
455+
397456
It 'Invalid parameters read from STDIN result in error' {
398457
$params = @{
399458
osFamily = 'Windows'
@@ -403,7 +462,7 @@ Describe 'Parameters tests' {
403462
$LASTEXITCODE | Should -Be 4
404463
$out | Should -BeNullOrEmpty
405464
$errorMessage = Get-Content -Path $TestDrive/error.log -Raw
406-
$errorMessage | Should -BeLike "*ERROR*Parameter input failure: JSON: missing field ````parameters````*"
465+
$errorMessage | Should -BeLike "*ERROR*Invalid parameters format: missing field ````parameters````*"
407466
}
408467

409468
It 'Parameters can reference other parameters in defaultValue: simple nested' {
@@ -935,7 +994,7 @@ parameters:
935994
}
936995
else {
937996
$expectedOutput = "{0}-{1}" -f $fileValue, $inlineValue
938-
}
997+
}
939998
$out.results[0].result.actualState.output | Should -BeExactly $expectedOutput
940999
}
9411000

extensions/bicep/.project.data.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"Kind": "Extension",
44
"CopyFiles": {
55
"All": [
6-
"bicep.dsc.extension.json"
6+
"bicep.dsc.extension.json",
7+
"bicepparams.dsc.extension.json"
78
]
89
}
910
}

extensions/bicep/bicep.tests.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,12 @@ resource invalid 'Microsoft.DSC.Extension/Bicep:1.0' = {
9494
$content | Should -Match "Importing file '$bicepFile' with extension 'Microsoft.DSC.Extension/Bicep'"
9595
$content | Should -Match "BCP033"
9696
}
97+
98+
It 'Example bicep parameters file should work' {
99+
$bicepFile = Resolve-Path -Path "$PSScriptRoot\..\..\dsc\examples\hello_world.dsc.bicep"
100+
$bicepParamFile = Resolve-Path -Path "$PSScriptRoot\..\..\dsc\examples\hello_world.dsc.bicepparam"
101+
$out = dsc -l trace config --parameters-file $bicepParamFile get --file $bicepFile 2>$TestDrive/error.log | ConvertFrom-Json
102+
$LASTEXITCODE | Should -Be 0 -Because (Get-Content -Path $TestDrive/error.log -Raw | Out-String)
103+
$out.results[0].result.actualState.output | Should -BeExactly 'This is a parameterized hello world!'
104+
}
97105
}

0 commit comments

Comments
 (0)