powershellazure-automationdsc

Composite DSC Resources not Exporting in Azure Automation


I'm trying to build my first composite DSC resource module for use in Azure Automation, and for the life of me, I cannot figure out what dumb thing I am overlooking which is preventing my DSC resources from being exported, or usable in a test configuration I've created. My first attempt was big and fancy and had params and imported other DSCResouces and was great and impressive, and didn't work at all.

So I decided to create a super simple config using code blocks from my non-Composite configurations, which all work fine. I zipped up everything listed below, imported it into my Azure Automation Modules, and it has no activities exported. There are no errors, nothing seems to not be happy, but nothing happens. The module is listed, but it doesn't do anything.

Running a test config against it fails saying it cannot import the module DefaultEnvironment, try importing the module.

I have tried with both of the following configs, both fail for the same reason:

configuration testdscconfig {
    Import-Module TestDSC
    Import-DscResource -Name DefaultRegistry
    Import-DscResource -Name DefaultEnvironment

    node localhost {
        DefaultEnvironment SetDefaultEnvironment {}
        DefaultRegistry SetDefaultRegistry {}
    }
}

and

configuration testdscconfig {
    Import-DSCResource -ModuleName TestDSC

    node localhost {
        DefaultEnvironment SetDefaultEnvironment {}
        DefaultRegistry SetDefaultRegistry {}
    }
}

My Composite DSC Config is structured like so:

TESTDSC
│   TestDSC.psd1
│   TestDSC.psm1
│
└───DSCResources
    ├───DefaultEnvironment
    │       DefaultEnvironment.psd1
    │       DefaultEnvironment.schema.psm1
    │
    └───DefaultRegistry
            Defaultregistry.psd1
            DefaultRegistry.schema.psm1

TestDSC.psm1 is an empty file. TestDSC.psd1 contains:

 @{  
    RootModule = "TestDSC.psm1"
    ModuleVersion = '0.0.8'
    GUID = <GUID>    
    Author = 'RobbieCrash'    
    CompanyName = 'Noncorp'
    
    # DSC resources to export from this module
    DscResourcesToExport = @(
        'DefaultEnvironment' 
        'DefaultRegistry'
    )
}

DSCResources\DefaultRegistry\DefaultRegistry.psd1:

@{RootModule="DefaultRegistry.schema.psm1"}

DSCResources\DefaultRegistry\DefaultRegistry.schema.psm1:

Configuration DefaultRegistry {
    Registry SecureDotNetCryptox64 {
        Ensure              =   "Present"
        Key                 =   "HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319\"
        ValueName           =   "SchUseStrongCrypto"
        ValueData           =   "1"
    }

    Registry SecureDotNetCryptox86 {
        Ensure              =   "Present"
        Key                 =   "HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319"
        ValueName           =   'SchUseStrongCrypto' 
        ValueData           =   '1'
    }
}

DefaultEnvironment is setup the same, with a seemingly innocuous Configuration block. Removing one or the other makes no difference, compiling fails and no resources are exported.

I've tried setting the RootModule= to be ".\Resource.schema.psm1" and "Resource.schema.psm1", verified cases, verified there's no wonky anything in the code, or typos, etc.

I'm positive I've missed some important detail somewhere, but after going through 20 different articles, and StackExchange/related threads, I'm sitting here dumb and cross eyed about what I must be missing.


Solution

  • Following on from above, I've done some testing, and the minimum requirement is to have RootModule and ModuleVersion defined, so DefaultRegistry.psd1 could be:

    @{
      RootModule    = 'DefaultRegistry.schema.psm1'
      ModuleVersion = '1.0.0'
    }