PowerShell / DSC

This repo is for the DSC v3 project
MIT License
200 stars 29 forks source link

Create JSON/YAML for configs that only use /*powershell adapter, from PowerShell script #396

Open mgreenegit opened 5 months ago

mgreenegit commented 5 months ago

Summary of the new feature / enhancement

To help preserve compatibility with existing configurations, it would help if a configuration .ps1 script could create JSON/YAML config and setup the PowerShell or WindowsPowerShell adapter. This will require a lot of feedback to get right, so creating this issue as a placeholder.

michaeltlombardi commented 5 months ago

@mgreenegit can you elaborate on this a bit more? Is this something like:

./new-dscv3config.ps1 -Name MyConfig
Get-Content -Path ./MyConfig.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: PowerShell DSC resources
  type: Microsoft.DSC/PowerShell
  properties:
    resources:
    - name: <INSTANCE_NAME>
      type: <PSDSC_MODULE_NAME>/<PSDSC_RESOURCE_NAME>
      properties:
        PropertyName: PropertyValue

Or is it meant to investigate the contents of a DSCv1.1/v2 configuration-creating script and emit the equivalent YAML?

For example, converting this:

Configuration MyDscConfiguration {
    Environment FirstEnvironmentVariable {
        Ensure = 'Present'
        Name   = 'Foo'
        Value  = 'Example'
    }

    Environment SecondEnvironmentVariable {
        Ensure = 'Present'
        Name   = 'Bar'
        Value  = 'Another'
    }
}

into this:

$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: MyDscConfiguration
  type: Microsoft.DSC/PowerShell
  properties:
    resources:
    - name: FirstEnvironmentVariable
      type: PSDscResources/Environment
      properties:
        Name: Foo
        Ensure: Present
        Value: Example
    - name: SecondEnvironmentVariable
      type: PSDscResources/Environment
      properties:
        Name: Bar
        Ensure: Present
        Value: Another

Or something else?

I'm also not sure what you mean by "setup the PowerShell or WindowsPowerShell adapter" in this case.