Skip to content

Commit

Permalink
(CAT-1617) - Always load vendored module in PSModulePath
Browse files Browse the repository at this point in the history
Prior to this commit, the vendored dsc module would only be loading into
the PSModulePath Env variable if the dsc resource type was implemented
as a Class.

Now that DSC Modules seem to be taking the approach of abstracting the
DscResource.Base module into a seperate module which is then imported,
we need to alter the PSModulePath Env variable to include the vendored
modules path to ensure these modules are imported as expected.
  • Loading branch information
jordanbreen28 committed Dec 12, 2023
1 parent 3f9f9e8 commit 8467b66
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,8 @@ def interpolate_variables(string)
modified_string
end

# Parses a resource definition (as from `invocable_resource`) and, if the resource is implemented
# as a PowerShell class, ensures the System environment variable for PSModulePath is munged to
# Parses a resource definition (as from `invocable_resource`) and

Check failure on line 659 in lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 2.7 | puppet ~> 7.0) / spec

Layout/TrailingWhitespace: Trailing whitespace detected.

Check failure on line 659 in lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 3.2 | puppet ~> 8.0) / spec

Layout/TrailingWhitespace: Trailing whitespace detected.
# ensures the System environment variable for PSModulePath is munged to
# include the vendored PowerShell modules. Due to a bug in PSDesiredStateConfiguration, class-based
# DSC Resources cannot be called via Invoke-DscResource by path, only by module name, *and* the
# module must be discoverable in the system-level PSModulePath. The postscript for invocation has
Expand All @@ -666,8 +666,6 @@ def interpolate_variables(string)
# @param resource [Hash] a hash with the information needed to run `Invoke-DscResource`
# @return [String] A multi-line string which sets the PSModulePath at the system level
def munge_psmodulepath(resource)
return unless resource[:dscmeta_resource_implementation] == 'Class'

vendor_path = resource[:vendored_modules_path].tr('/', '\\')
<<~MUNGE_PSMODULEPATH.strip
$UnmungedPSModulePath = [System.Environment]::GetEnvironmentVariable('PSModulePath','machine')
Expand Down

0 comments on commit 8467b66

Please sign in to comment.