How do you add resources to a module generated with New-SampleModule?
- Dominant language
- PowerShell
- Stars
- 243
- Forks
- 46
- Avg merge
- 1h 41m
- Merged PRs (30d)
- 1
Description
I'm developing a module to provide some DSC resources, and then I discovered sampler. Since it's a good idea to do the same things as the community around something, I've been trying to adapt/port my module into one compatible with sampler, but I'm running into some confusion.
I created a module using this command:
```powershell
New-SampleModule -DestinationPath . -ModuleType newDscCommunity -ModuleName MyModule
```
# MOF resources
I'd like to add a resource so I ran this command:
```powershell
> Add-Sample -Sample cAzResourceGroup
____ _ _
| _ \| | __ _ ___| |_ ___ _ __
| |_) | |/ _` / __| __/ _ \ '__|
| __/| | (_| \__ \ || __/ |
|_| |_|\__,_|___/\__\___|_|
v1.1.3
==================================================
Name of your Resource (MyResource): MyResource2
Name of your module (MyModule): MyModule2
What is your source folder? (source):
Destination path: C:\src\git\Gates-Environment-Tools-2
Identical source\DSCResources\DSC_Folder\DSC_Folder.psm1
Identical source\DSCResources\DSC_Folder\DSC_Folder.schema.mof
Identical source\DSCResources\DSC_Folder\en-US\DSC_Folder.strings.psd1
Identical source\Modules\Folder.Common\Folder.Common.psm1
Conflict tests\Unit\DSCResources\DSC_Folder.tests.ps1
Plaster file conflict
Overwrite C:\src\git\Gates-Environment-Tools-2\tests\Unit\DSCResources\DSC_Folder.tests.ps1
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
Identical tests\Unit\Modules\Folder.Common.tests.ps1
```
It seems to be adding the DSC_Folder resource no matter what details I give it but I'm not sure whether I'm doing this right.
# Class resources
I tried with a class based resource:
```
Add-Sample -Sample ClassResource -ResourceName cAzResourceGroup
```
This did add something but didn't update `DscResourcesToExport` in the containing module .psd1. The initial tests also failed:
```
Describing Testing Get Method
Context When the configuration is absent
[+] Should return the state as absent 75ms
[-] Should return the same values as present in properties 18ms
Expected $true, but got $false.
73: $getMethodResourceResult.PropertyMandatory | Should -Be $script:instanceDesiredState.PropertyMandatory
at , C:\src\git\sampledsc\cCliniSys.Azure2\tests\Unit\Classes\DSC_cAzResourceGroup.tests.ps1: line 73
[+] Should return $false or $null respectively for the rest of the properties 11ms
[+] Should return Reason because the item is absent 17ms
Context When the configuration is present
[+] Should return the state as present 42ms
[-] Should return the same values as present in properties 15ms
Expected $true, but got $false.
108: $getMethodResourceResult.PropertyMandatory | Should -Be $script:instanceDesiredState.PropertyMandatory
at , C:\src\git\sampledsc\cCliniSys.Azure2\tests\Unit\Classes\DSC_cAzResourceGroup.tests.ps1: line 108
```
What's the extra thing I need to do to make it work?
# Importing existing MOF resources
I also have some existing (MOF) resources I'd like to add, but I'm not sure how to hook them into the build. Just copying them into the DSCResources folder didn't seem to do it.
Could someone point me in the right direction to add new resources, and add our existing resources into the module as well?
Contributor guide
Assessment
This issue has not been assessed yet.