Skip to content

Commit

Permalink
More updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ykuijs committed Nov 7, 2023
1 parent 39164e1 commit b6ce021
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 116 deletions.
107 changes: 3 additions & 104 deletions .build/tasks/Create-CompositeResource.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ task Generate_Composite_Resource_Module {
. Set-SamplerTaskVariable

"`tOutput Path = '$OutputDirectory'"
""

Write-Build White 'Generating Composite Resource Module'

Install-Module -Name Microsoft365DSC -RequiredVersion $env:ModuleVersion -Scope AllUsers

$result = New-CompositeResourceModule -OutputPath $OutputDirectory

if ($result)
Expand All @@ -72,108 +75,4 @@ task Generate_Composite_Resource_Module {
{
throw "Error occurred during module generation! Please check the log output."
}

# $osShortName = Get-OperatingSystemShortName

# $powerShellVersion = 'PSv.{0}' -f $PSVersionTable.PSVersion

# $moduleFileName = '{0}.psm1' -f $ProjectName

# $PesterOutputFolder = Get-SamplerAbsolutePath -Path $PesterOutputFolder -RelativeTo $OutputDirectory

# "`tPester Output Folder = '$PesterOutputFolder'"

# $GetCodeCoverageThresholdParameters = @{
# RuntimeCodeCoverageThreshold = $CodeCoverageThreshold
# BuildInfo = $BuildInfo
# }

# $CodeCoverageThreshold = Get-CodeCoverageThreshold @GetCodeCoverageThresholdParameters

# if (-not $CodeCoverageThreshold)
# {
# $CodeCoverageThreshold = 0
# }

# "`tCode Coverage Threshold = '$CodeCoverageThreshold'"

# if ($CodeCoverageThreshold -gt 0)
# {
# $getPesterOutputFileFileNameParameters = @{
# ProjectName = $ProjectName
# ModuleVersion = $ModuleVersion
# OsShortName = $osShortName
# PowerShellVersion = $powerShellVersion
# }

# $pesterOutputFileFileName = Get-PesterOutputFileFileName @getPesterOutputFileFileNameParameters

# $getCodeCoverageOutputFile = @{
# BuildInfo = $BuildInfo
# PesterOutputFolder = $PesterOutputFolder
# }

# $CodeCoverageOutputFile = Get-SamplerCodeCoverageOutputFile @getCodeCoverageOutputFile

# if (-not $CodeCoverageOutputFile)
# {
# $CodeCoverageOutputFile = (Join-Path -Path $PesterOutputFolder -ChildPath "CodeCov_$pesterOutputFileFileName")
# }

# "`tCode Coverage Output File = $CodeCoverageOutputFile"

# $CodeCoverageMergedOutputFile = 'CodeCov_Merged.xml'

# if ($BuildInfo.CodeCoverage.CodeCoverageMergedOutputFile)
# {
# $CodeCoverageMergedOutputFile = $BuildInfo.CodeCoverage.CodeCoverageMergedOutputFile
# }

# $CodeCoverageMergedOutputFile = Get-SamplerAbsolutePath -Path $CodeCoverageMergedOutputFile -RelativeTo $PesterOutputFolder

# "`tCode Coverage Merge Output File = $CodeCoverageMergedOutputFile"

# $CodeCoverageFilePattern = 'Codecov*.xml'

# if ($BuildInfo.ContainsKey('CodeCoverage') -and $BuildInfo.CodeCoverage.ContainsKey('CodeCoverageFilePattern'))
# {
# $CodeCoverageFilePattern = $BuildInfo.CodeCoverage.CodeCoverageFilePattern
# }

# "`tCode Coverage File Pattern = $CodeCoverageFilePattern"

# if (-not [System.String]::IsNullOrEmpty($CodeCoverageFilePattern))
# {
# $codecovFiles = Get-ChildItem -Path $PesterOutputFolder -Include $CodeCoverageFilePattern -Recurse
# }

# "`tMerging Code Coverage Files = '{0}'" -f ($codecovFiles.FullName -join ', ')
# ""

# if (Test-Path -Path $CodeCoverageMergedOutputFile)
# {
# Write-Build Yellow "File $CodeCoverageMergedOutputFile found, deleting file."

# Remove-Item -Path $CodeCoverageMergedOutputFile -Force
# }

# Write-Build White "Processing folder: $OutputDirectory"

# if ($codecovFiles.Count -gt 1)
# {
# Write-Build DarkGray "Started merging $($codecovFiles.Count) code coverage files!"

# Start-CodeCoverageMerge -Files $codecovFiles -TargetFile $CodeCoverageMergedOutputFile

# Write-Build Green "Merge completed. Saved merge result to: $CodeCoverageMergedOutputFile"
# }
# else
# {
# throw "Found $($codecovFiles.Count) code coverage file. Need at least two files to merge."
# }
# }
# else
# {
# Write-Build White 'Code coverage is not enabled, skipping.'
# }
}
38 changes: 29 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,32 @@ M365DSC CRG = Microsoft365DSC Composite Resource Generator

This module will be able to generate Composite Resources for Microsoft365DSC, which can be used on Microsoft365DSC deployments. These Composite Resources are used in the Microsoft365DSC whitepaper ["Managing Microsoft 365 in true DevOps style with Microsoft365DSC and Azure DevOps"](https://aka.ms/m365dscwhitepaper).

DOCUMENTATION!!
UniqueID -> Why is this added
How does it work
Plural vs Singular names
Create a CR for each workload

Exceptions:
Only resources with CertThumbprint (TeamsOrgWideAppSettings, O365SearchAndIntelligenceConfigurations, TeamsUserCallingSettings)
Filter M365DSCRuleEvaluation resource
## Installation

You can install this module from the PowerShell Gallery by executing the following command:

```powershell
Install-Module -Name M365DSC.CRG
```

## Usage

This module publishes one function called `New-CompositeResourceModule`. This function will generate a module that contains composite resources for each workload of Microsoft365DSC. The function requires one parameter `OutputPath`, which specifies the path where the module will be generated. The module will be named `M365DSC.CompositeResources`.

It also creates an example data file, which is included in the module. You can use the function `New-M365DSCExampleDataFile` to copy this file to a specific folder, where you can use it as a starting point of your own data file. It is recommended you use this file, since that already uses the correct naming conventions that the composite resources use.

### Important notes

The configuration data sometimes uses arrays of hashtables. In order to merge these items correctly, the code needs to know which items are the same. This is done by using the `Id` or `Identity` properties. When the specific DSC resource does not have one of these properties, the code will look for the `UniqueID` property. This property is removed from the hashtable before it is used in the composite resource.

Where DSC resources use singular names in the resource names, like `AADAdministrativeUnit`. However in the configuration data, these names are made plural, like `AADAdministrativeUnits`.

The code will implement each DSC resource found in Microsoft365DSC, but there are a few exceptions. The following resources are not implemented:

- Resources that do not support CertThumbprint. Currently these are O365SearchAndIntelligenceConfigurations, TeamsOrgWideAppSettings and TeamsUserCallingSettings.
- The M365DSCRuleEvaluation resource does not have an equivalent in Microsoft 365 but is used to evaluate compliancy rules.

## ToDo

- Cache errors and output overview at the end.
- Update output logging
2 changes: 1 addition & 1 deletion source/M365DSC.CRG.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ GUID = '29313631-3fdf-45b7-a8b7-00e34b280983'
Author = 'Yorick Kuijs'

# Company or vendor of this module
CompanyName = 'Yorick Kuijs'
CompanyName = 'Microsoft'

# Copyright statement for this module
Copyright = '(c) 2023 Yorick Kuijs. All rights reserved.'
Expand Down
47 changes: 46 additions & 1 deletion source/Private/Initialize-Module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,71 @@ function Initialize-Module

# Create the module manifest content
$moduleManifestString = [System.Text.StringBuilder]::new()
[void]$moduleManifestString.AppendLine('#')
[void]$moduleManifestString.AppendLine("# Module manifest for module 'M365DSC.CompositeResources'")
[void]$moduleManifestString.AppendLine('#')
[void]$moduleManifestString.AppendLine("# Generated on: $(Get-Date -f "d-M-yyyy")")
[void]$moduleManifestString.AppendLine('#')
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine('@{')
[void]$moduleManifestString.AppendLine(' # Script module or binary module file associated with this manifest.')
[void]$moduleManifestString.AppendLine(" RootModule = 'M365DSC.CompositeResources.psm1'")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' # Version number of this module.')
[void]$moduleManifestString.AppendLine(" ModuleVersion = '$Version'")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' # ID used to uniquely identify this module')
[void]$moduleManifestString.AppendLine(" GUID = '8c07a295-6a8d-465d-933d-9f598d77fdfb'")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' # Author of this module')
[void]$moduleManifestString.AppendLine(" Author = 'Yorick Kuijs'")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' # Company or vendor of this module')
[void]$moduleManifestString.AppendLine(" CompanyName = 'Microsoft'")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' # Modules that must be imported into the global environment prior to importing this module')
[void]$moduleManifestString.AppendLine(" RequiredModules = @('DscBuildHelpers', @{ModuleName='DscBuildHelpers'; RequiredVersion='0.2.1'; GUID='23ccd4bf-0a52-4077-986f-c153893e5a6a'})")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.')
[void]$moduleManifestString.AppendLine(" FunctionsToExport = @('New-M365DSCExampleDataFile')")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.')
[void]$moduleManifestString.AppendLine(" CmdletsToExport = @()")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' # Variables to export from this module')
[void]$moduleManifestString.AppendLine(" VariablesToExport = @()")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.')
[void]$moduleManifestString.AppendLine(" AliasesToExport = @()")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' # DSC resources to export from this module')
[void]$moduleManifestString.AppendLine(" DscResourcesToExport = @('*')")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' # Description of the functionality provided by this module')
[void]$moduleManifestString.AppendLine(" Description = 'DSC composite resource for configuring Microsoft 365'")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' # Minimum version of the Windows PowerShell engine required by this module')
[void]$moduleManifestString.AppendLine(" PowerShellVersion = '5.0'")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.')
[void]$moduleManifestString.AppendLine(' PrivateData = @{')
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' PSData = @{')
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(" Tags = @('DSC', 'Configuration', 'Composite', 'Resource', 'Microsoft365DSC')")
[void]$moduleManifestString.AppendLine(' # Tags applied to this module. These help with module discovery in online galleries.')
[void]$moduleManifestString.AppendLine(" Tags = @('DSC', 'DesiredStateConfiguration', 'M365DSC', 'Microsoft365DSC', 'Microsoft365', 'CompositeResource')")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' # A URL to the license for this module.')
[void]$moduleManifestString.AppendLine(" LicenseUri = 'https://github.com/ykuijs/M365DSC.CompositeResources/blob/main/LICENSE'")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' # A URL to the main website for this project.')
[void]$moduleManifestString.AppendLine(" ProjectUri = 'https://github.com/ykuijs/M365DSC.CompositeResources'")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' # A URL to an icon representing this module.')
[void]$moduleManifestString.AppendLine(" IconUri = 'https://github.com/microsoft/Microsoft365DSC/blob/Dev/Modules/Microsoft365DSC/Dependencies/Images/Logo.png?raw=true'")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(' # ReleaseNotes of this module')
[void]$moduleManifestString.AppendLine(" ReleaseNotes = 'Module belongs to Microsoft365DSC v$($Version)'")
[void]$moduleManifestString.AppendLine('')
[void]$moduleManifestString.AppendLine(" ExternalModuleDependencies = @('Microsoft365DSC')")
[void]$moduleManifestString.AppendLine('')
Expand Down
2 changes: 1 addition & 1 deletion source/Public/New-CompositeResourceModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ function New-CompositeResourceModule
Write-Host -Object 'Writing ConfigurationData file' -ForegroundColor Cyan
$psdStringData = "# ($(Get-Date -f 'yyyy-MM-dd HH:mm:ss')) Generated using Microsoft365DSC v$($m365Module.Version)`n"
$psdStringData += $configData | ConvertTo-Psd
$psdPath = Join-Path -Path $OutputPath -ChildPath 'M365ConfigurationDataExample.psd1'
$psdPath = Join-Path -Path $OutputPath -ChildPath "M365DSC.CompositeResources\$($m365Module.Version)\M365ConfigurationDataExample.psd1"
Set-Content -Path $psdPath -Value $psdStringData
return $true
}
Expand Down

0 comments on commit b6ce021

Please sign in to comment.