Authoring DSCv3 config docs with PowerShell #1487
Replies: 2 comments 2 replies
-
|
I think it's important to note that even if we eventually decide to present a set of low-level commands for constructing and operating on DSC configuration documents we'll still need the data types defined. I think an initial release that defines the data types is perfectly valid and would already provide a lot of value. I think there's still value in providing commands to operate on these types, like: $config = [Microsoft.DSC.Configuration]@{
resources = @(
[Microsoft.DSC.Resource]@{
name = 'SSHD service'
properties = [DSC.Microsoft.Windows.Service]@{
name = 'sshd'
status = 'Running'
}
}
}
foreach ($resource in $resources) {
if ($resource.tags -notcontains 'bastion') { continue }
$config | Add-DscResourceInstance -instance $resource.Instance)
}
$config | Export-DscConfigurationDocument -Path ./example.dsc.config.yamlBut since defining the types is a prerequisite for any useful commands, I think focusing on those types and their ergonomics makes a lot of sense. I also think that it's okay if the eventual module is PowerShell 7+ only - authoring a configuration document is a very different concern from supporting Windows PowerShell for a resource. |
Beta Was this translation helpful? Give feedback.
-
|
How about a DSL like Pester?
Sample authoring experience Import-DSCResource
if ($IsWindows) {
$serviceState = @(
@{ Name = 'sshd'; Status = 'Running' }
@{ Name = 'winrm'; Status = 'Running' }
)
$serviceConfig = $serviceState | ForEach-Object {
Microsoft.Windows.Service {
Name = $_.Name
Status = $_.State
}
}
}
## Other option where the type expands the input
$serviceConfig = $serviceState | Microsoft.Windows.Service ## This will bind by PropertyName
$psResource = PSResource {
Name = 'Pester'
Version = '5.1.0'
}
$resources = @($serviceConfig, $psResource)
Microsoft.DSC.Configuration -Resources $resources | Export-DSCConfigurationDocument -Path ./deploy.config.yml
## Or by pipeline binding
$serviceConfig, $psresource | Microsoft.DSC.Configuration | Export-DSCConfigurationDocument -Path ./deploy.config.yml
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
There's at least 3 aspects to this:
It might be easiest to not have cmdlets, but leverage .NET types created by a PS module because PS7 supports intellisense for type properties:
An open question, is there a way for
dependsOnto have intellisense to show all the defined resources? Since the config type hasn't been constructed yet, there's a chicken-and-egg problem.Ideally, we could use AST parsing to convert PS
params()intoparameters, but need to explore if the mapping works completely.For resource properties, I think it would be easier if this module runs
dsc resource listanddsc resource list --adapter '*'to get all of them and generate .NET types under a DSC namespace such asDSC.<typeNamespace>.<typeName>. There IS a risk of name collision here if a DSC resource type has a<typeName>that is also part of a<typeNamespace>, but I'd expect that to be rare and something we wouldn't recommend. With this model, PS7 already has intellisense for properties using type conversion with a hashtable:Expressions ideally would be a type conversion from a PS scriptblock into an expression string:
This should result in the expression:
[concat(systemRoot(), '\Windows\System32')]. During type conversion of the script block, theMicrosoft.DSC.Expressiontype would validate that any used PS syntax is supported and can be transpiled to a DSC expression.Beta Was this translation helpful? Give feedback.
All reactions