DSC icon indicating copy to clipboard operation
DSC copied to clipboard

config validate command needs to check for duplicate resource names in configuration document

Open fl0p3k opened this issue 7 months ago • 1 comments

Summary of the new feature / enhancement

In order to avoid errors at runtime, the dsc config validate should detect and provide appropriate error response when a resource name is duplicated in a configuration document.

Configuration:

{
"$schema": "https://aka.ms/dsc/schemas/v3/bundled/config/document.json",
"resources": [
{
"type": "Microsoft.Windows/Registry",
"name": "EnsureTest1Value",
"properties": {
"keyPath": "HKEY_LOCAL_MACHINE\SOFTWARE\TEST",
"valueName": "Test1",
"valueData": { "DWord": 1 },
"_exist": true
}
},
{
"type": "Microsoft.Windows/Registry",
"name": "EnsureTest2Value",
"properties": {
"keyPath": "HKEY_LOCAL_MACHINE\SOFTWARE\TEST",
"valueName": "Test2",
"valueData": { "String": "Hello World!" },
"_exist": true
}
},
{
"type": "Microsoft.Windows/Registry",
"name": "EnsureTest1Value",
"properties": {
"keyPath": "HKEY_LOCAL_MACHINE\SOFTWARE\TEST",
"valueName": "Test",
"valueData": { "String": "Hello World!" },
"_exist": false
}
}
]
}

This below should return false with a reason as duplicate resource name

dsc config validate --file C:\dsc\Demo1.json
valid: true
reason: null

Proposed technical implementation details (optional)

No response

fl0p3k avatar May 28 '25 17:05 fl0p3k

The validate sub-command is used by dsc itself to validate the input matches the JSONSchema. I can see how validate would be useful to users directly. I think what we should do is add a --schema-only to maintain the current behavior and update the group resource manifests to use this and add additional validation like duplicate resource names to this sub-command eventually having more static analysis capabilities.

SteveL-MSFT avatar May 28 '25 19:05 SteveL-MSFT