Reputation: 407
I'm working on a DSC composite resource, but I can't seem to get it working. My code:
E:\Dev\DSCResources\run.ps1:
Import-Module Test -Force
Configuration Run
{
Import-DscResource -ModuleName Test
Node localhost
{
Test Common {
TestString = "blabla"
}
}
}
Run
And the composite resource:
E:\Dev\DSCResources\Test\test.schema.psm1:
Configuration Test {
Param (
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$Teststring
)
Log Example {
Message = $Teststring
}
}
E:\Dev\DSCResources\Test\test.psd1:
#
# Module manifest for module 'test'
#
# Generated by: Administrator
#
# Generated on: 3/12/2014
#
@{
# Script module or binary module file associated with this manifest.
RootModule = 'test.schema.psm1'
# Version number of this module.
ModuleVersion = '1.0'
# ID used to uniquely identify this module
GUID = 'a0c8ed64-00bc-4112-997f-d65d567bc043'
# Author of this module
Author = 'Administrator'
# Company or vendor of this module
CompanyName = 'Unknown'
# Copyright statement for this module
Copyright = '(c) 2014 Administrator. All rights reserved.'
# Description of the functionality provided by this module
# Description = ''
# Minimum version of the Windows PowerShell engine required by this module
# PowerShellVersion = ''
# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''
# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''
# Minimum version of Microsoft .NET Framework required by this module
# DotNetFrameworkVersion = ''
# Minimum version of the common language runtime (CLR) required by this module
# CLRVersion = ''
# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''
# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()
# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()
# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()
# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @("")
# Functions to export from this module
#FunctionsToExport = '*'
# Cmdlets to export from this module
#CmdletsToExport = '*'
# Variables to export from this module
#VariablesToExport = '*'
# Aliases to export from this module
#AliasesToExport = '*'
# List of all modules packaged with this module
# ModuleList = @()
# List of all files packaged with this module
# FileList = @()
# Private data to pass to the module specified in RootModule/ModuleToProcess
# PrivateData = ''
# HelpInfo URI of this module
# HelpInfoURI = ''
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''
}
But the parameters don't get supplied, and I get the following output:
cmdlet Test at command pipeline position 1
Supply values for the following parameters:
Teststring:
So it seems like the composite resource does work, but the passed parameters are not read. So it bails out and asks me to manually input the parameters.
Are composite resources broken? Or am I doing something wrong?
Upvotes: 2
Views: 3229
Reputation: 4838
After your update I could successfully reproduce your problem, after which I couldn't get my original configuration working again, making me believe I made some kind of error in my original test. In the following examples, I will use BaseConfig
for config name and MyParameter
for parameter name.
In order to create a longer description with line-by-line instructions, I wrote a blog post on the subject: http://robertwesterlund.net/post/2014/03/12/creating-a-composite-dsc-configuration-with-parameters
When a Composite Configuration is created as an ordinary module (directly in the C:\Program Files\WindowsPowerShell\Modules\MyModuleName
, for example), it seems like it behaves like an ordinary Cmdlet. This means, to pass parameters to the composite configuration I had to do:
Import-DscResource -ModuleName BaseConfig
Node localhost
{
BaseConfig Common -MyParameter "My Parameter Value"
{
}
}
I must admit that I don't know if this would behave as expected for a DSC resource for other parts.
The way I wanted to write the configuration was the following:
Import-DscResource -Name BaseConfig
Node localhost
{
BaseConfig Common
{
MyParameter = "My Parameter Value"
}
}
(Notice that the Import-DscResource
also differs.)
To get this working, I had to make a dummy container module (which, of course, could contain implementation if necessary, but I only created an empty psm1
file and a psd1
file pointing to that psm1 file. After making the container module without implementation, I then made a DSC Resource module (located in the MyContainerModule\DSCResources\MyCompositeConfiguration
folder) for the composite configuration. After this it worked just as expected. This is probably the correct way to create a composite configuration.
Upvotes: 1