Azure / GuestConfiguration

PowerShell module for creating, testing, and publishing custom Guest Configuration
MIT License
5 stars 2 forks source link

Add support for native DSC resource compilation with PSDSCV3 module #261

Closed bagajjal closed 2 years ago

bagajjal commented 2 years ago

Problem statement As part of running PowerShell DSC resources on Linux, we introduced PSDSCV3 module.

PSDSCV3 module supports ONLY class based resources. PSDSCV2 module supports both script based, class based resources.

PowerShell 7.2+ doesn't come with PSDSC module. Users must download PSDSC module for DSC functionality from PSGallery. Users can choose either PSDSCV2 or PSDSCV3 module.

The native DSC resource representation is defined as a script based resource at $GuestConfiguration\source\DscResources\MSFT_ChefInSpecResource\MSFT_ChefInSpecResource.schema.mof. Given PSDSCV3 only supports class based resources, this introduced a regression.

Solution

  1. Add class based representation of native DSC resource "MSFT_ChefInSpecResource" in the GuestConfiguration.psm1.
  2. After the build task is complete do the following a. Rename the MSFT_ChefInSpecResource.schema.mof to MSFT_ChefInSpecResource.schema. This is required otherwise during native resource compilation the "MSFT_ChefInSpecResource" DSC resource will be found in two different places. It's shown as an error and customers doesn't know which one to pick. b. Remove the AliasesToExport in GuestConfiguration.psd1. This is required to surface the new class based resource added in GuestConfiguration.psm1. There is a historical bug in the PowerShell which doesn't surface the class based resource defined in GuestConfiguration.psm1. Based on the PowerShell team recommendation, deleting AliasesToExport will surface the newly added class based resource.

Testing Tested on all supported PowerShell versions with PSDSCV2 and PSDSCV3 modules. PSDSCV2 module is supported on PowerShell 6.2+. Please note PSV7.2 still supports PSDSCV2. PSDSCV3 module is supported on PowerShell 7.2+.

For all the below configurations, created the native resource and tested on the ubuntu VM.

On windows,

  1. PSV7.2 with PSDSCV2. Test output
  2. PSV7.2 with PSDSCV3. Test output
  3. PSV6.2 with PSDSCV2. Test output
  4. PS5.1 with PSDSCV1.1. Test output "Amit Saraf" requested to test using this. For this I have to modify GuestConfiguration.psd1 to change the minimum supported powershell version and minor change in GuestConfiguration.psm1.

    On Linux,

    1. PSV7.2 with PDSCV2. Test output

    2. PSV7.2 with PDSCV3. Test output

bagajjal commented 2 years ago

@kwirkykat , as we discussed offline, the devops build pipeline need some changes for this PR. Current devops pipeline calls the ".\build.ps1 -tasks pack" which does build, downloading agent, etc and publish the Nuget package before it returns to the place where I'm modifying the PSD1 and renaming the MSFT_ChefInspecResource.schema.mof to MSFT_ChefInspecResource.schema. Because of this my code changes doesn't take in effect.

To fix this we need to modify the build pipeline to call ".\build.ps1 -tasks build" and add a new task to do the rest of the tasks like downloading agent, publish the Nuget package, etc.

github-actions[bot] commented 2 years ago

This PR has not been updated within 14 days