Skip to content

Commit

Permalink
Merge pull request #99 from dsccommunity/CMBoundaryUpdate
Browse files Browse the repository at this point in the history
CMBoundaries: Adding support for new boundary types
  • Loading branch information
NEllis280 authored Sep 24, 2021
2 parents c82e49a + 3160b2a commit f1cd564
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed issue with CMAccounts with Get returning a string when only one account exists.
- Fixed issue with Boundary groups containing VPN type boundaries.

### Changed

- Added support for VPN and IPv6Prefix boundaries to the CMBoundaries resource.

## [1.0.2] - 2021-05-12

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ you are using apply and auto correct.
- **[String] Value** _(Key)_: Specifies the value for the boundary.
- **[String] DisplayName** _(Required)_: Specifies the display name of the boundary.
- **[String] Type** _(Required)_: Specifies the type of boundary.
- Values include: { ADSite | IPSubnet | IPRange
- Values include: { ADSite | IPSubnet | IPRange | VPN | IPv6Prefix }
- **[String] Ensure** _(Write)_: Specifies whether the boundary is present or
absent.
- Values include: { Present | Absent }
Expand Down
20 changes: 11 additions & 9 deletions source/DSCResources/DSC_CMBoundaries/DSC_CMBoundaries.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
Not used in Get-TargetResource.
.Parameter Type
Specifies the type of boundary ADSite, IPSubnet, or IPRange.
Specifies the type of boundary ADSite, IPSubnet, IPRange, VPN, or IPv6Prefix.
.Parameter Value
Specifies the value for the boundary.
Expand All @@ -38,7 +38,7 @@ function Get-TargetResource
$DisplayName,

[Parameter(Mandatory = $true)]
[ValidateSet('ADSite','IPSubnet','IPRange')]
[ValidateSet('ADSite','IPSubnet','IPRange','VPN','IPv6Prefix')]
[String]
$Type,

Expand All @@ -53,9 +53,11 @@ function Get-TargetResource

$convertBoundary = switch ($Type)
{
'IPSubnet' { '0' }
'AdSite' { '1' }
'IPRange' { '3' }
'IPSubnet' { '0' }
'AdSite' { '1' }
'IPv6Prefix' { '2' }
'IPRange' { '3' }
'Vpn' { '4' }
}

if ($Type -eq 'IPSubnet')
Expand Down Expand Up @@ -102,7 +104,7 @@ function Get-TargetResource
Specifies the display name of the boundary.
.Parameter Type
Specifies the type of boundary ADSite, IPSubnet, or IPRange.
Specifies the type of boundary ADSite, IPSubnet, IPRange, VPN, or IPv6Prefix.
.Parameter Value
Specifies the value for the boundary.
Expand All @@ -124,7 +126,7 @@ function Set-TargetResource
$DisplayName,

[Parameter(Mandatory = $true)]
[ValidateSet('ADSite','IPSubnet','IPRange')]
[ValidateSet('ADSite','IPSubnet','IPRange','VPN','IPv6Prefix')]
[String]
$Type,

Expand Down Expand Up @@ -187,7 +189,7 @@ function Set-TargetResource
Specifies the display name of the boundary.
.Parameter Type
Specifies the type of boundary ADSite, IPSubnet, or IPRange.
Specifies the type of boundary ADSite, IPSubnet, IPRange, VPN, or IPv6Prefix.
.Parameter Value
Specifies the value for the boundary.
Expand All @@ -210,7 +212,7 @@ function Test-TargetResource
$DisplayName,

[Parameter(Mandatory = $true)]
[ValidateSet('ADSite','IPSubnet','IPRange')]
[ValidateSet('ADSite','IPSubnet','IPRange','VPN','IPv6Prefix')]
[String]
$Type,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class DSC_CMBoundaries : OMI_BaseResource
{
[Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode;
[Key, Description("Specifies the value for the boundary.")] String Value;
[Key, Description("Specifies the type of boundary"), ValueMap {"ADSite","IPSubnet","IPRange"}, Values {"ADSite","IPSubnet","IPRange"}] String Type;
[Key, Description("Specifies the type of boundary"), ValueMap {"ADSite","IPSubnet","IPRange","VPN","IPv6Prefix"}, Values {"ADSite","IPSubnet","IPRange","VPN","IPv6Prefix"}] String Type;
[Required, Description("Specifies the display name of the boundary")] String DisplayName;
[Write, Description("Specifies whether the boundary is present or absent."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
[Read, Description("Specifies the SiteCode for the Configuration Manager site.")] String BoundaryID;
Expand Down
36 changes: 36 additions & 0 deletions source/Examples/Resources/CMBoundaries/CMBoundaries_Present.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,41 @@ Configuration Example
Value = '10.1.1.1-10.1.1.255'
Ensure = 'Present'
}

CMBoundaries ExampleVpn
{
SiteCode = 'Lab'
DisplayName = 'VPN AutoDetect'
Type = 'VPN'
Value = 'Auto:On'
Ensure = 'Present'
}

CMBoundaries ExampleVpnDescription
{
SiteCode = 'Lab'
DisplayName = 'VPN ConnectionDescription'
Type = 'VPN'
Value = 'Description:Contoso VPN'
Ensure = 'Present'
}

CMBoundaries ExampleVpnName
{
SiteCode = 'Lab'
DisplayName = 'VPN ConnectionName'
Type = 'VPN'
Value = 'Name:Contoso.com'
Ensure = 'Present'
}

CMBoundaries ExampleIPv6
{
SiteCode = 'Lab'
DisplayName = 'IPv6 1'
Type = 'IPv6Prefix'
Value = '2001:0DB8:0000:000b'
Ensure = 'Present'
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ function ConvertTo-CimBoundaries
{
'0' { 'IPSubnet' }
'1' { 'AdSite' }
'2' { 'IPv6Prefix' }
'3' { 'IPRange' }
'4' { 'VPN' }
'4' { 'Vpn' }
}

$cimProperties = @{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,6 @@ Configuration ConfigureSccm
DiscoverDistributionGroupMembership = `$CMGroupDiscovery.DiscoverDistributionGroupMembership
Start = `$CMGroupDiscovery.Start
ScheduleType = `$CMGroupDiscovery.ScheduleType
RefreshType = `$CMGroupDiscovery.RefreshType
RecurInterval = `$CMGroupDiscovery.RecurInterval
DayOfWeek = `$CMGroupDiscovery.DayOfWeek
}
Expand Down Expand Up @@ -1083,7 +1082,6 @@ Configuration ConfigureSccm
DiscoverDistributionGroupMembership = `$CMGroupDiscovery.DiscoverDistributionGroupMembership
Start = `$CMGroupDiscovery.Start
ScheduleType = `$CMGroupDiscovery.ScheduleType
RefreshType = `$CMGroupDiscovery.RefreshType
RecurInterval = `$CMGroupDiscovery.RecurInterval
DayOfWeek = `$CMGroupDiscovery.DayOfWeek
}
Expand Down Expand Up @@ -1175,7 +1173,6 @@ Configuration ConfigureSccm
DiscoverDistributionGroupMembership = `$CMGroupDiscovery.DiscoverDistributionGroupMembership
Start = `$CMGroupDiscovery.Start
ScheduleType = `$CMGroupDiscovery.ScheduleType
RefreshType = `$CMGroupDiscovery.RefreshType
RecurInterval = `$CMGroupDiscovery.RecurInterval
DayOfWeek = `$CMGroupDiscovery.DayOfWeek
}
Expand Down Expand Up @@ -1277,7 +1274,6 @@ Configuration ConfigureSccm
DiscoverDistributionGroupMembership = `$CMGroupDiscovery.DiscoverDistributionGroupMembership
Start = `$CMGroupDiscovery.Start
ScheduleType = `$CMGroupDiscovery.ScheduleType
RefreshType = `$CMGroupDiscovery.RefreshType
RecurInterval = `$CMGroupDiscovery.RecurInterval
DayOfWeek = `$CMGroupDiscovery.DayOfWeek
}
Expand Down Expand Up @@ -1376,7 +1372,6 @@ Configuration ConfigureSccm
DiscoverDistributionGroupMembership = `$CMGroupDiscovery.DiscoverDistributionGroupMembership
Start = `$CMGroupDiscovery.Start
ScheduleType = `$CMGroupDiscovery.ScheduleType
RefreshType = `$CMGroupDiscovery.RefreshType
RecurInterval = `$CMGroupDiscovery.RecurInterval
DayOfWeek = `$CMGroupDiscovery.DayOfWeek
}
Expand Down Expand Up @@ -1473,7 +1468,6 @@ Configuration ConfigureSccm
DiscoverDistributionGroupMembership = `$CMGroupDiscovery.DiscoverDistributionGroupMembership
Start = `$CMGroupDiscovery.Start
ScheduleType = `$CMGroupDiscovery.ScheduleType
RefreshType = `$CMGroupDiscovery.RefreshType
RecurInterval = `$CMGroupDiscovery.RecurInterval
DayOfWeek = `$CMGroupDiscovery.DayOfWeek
}
Expand Down
58 changes: 58 additions & 0 deletions tests/Unit/CMBoundaries.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,38 @@ try
Ensure = 'Absent'
}

$inputVpnPresent = @{
SiteCode = 'Lab'
DisplayName = 'VPN 1'
Type = 'VPN'
Value = 'Auto:On'
}

$inputIPv6Present = @{
SiteCode = 'Lab'
DisplayName = 'IPv6 1'
Type = 'IPv6Prefix'
Value = '2001:0DB8:0000:000b'
}

$boundaryVpnReturn = @(
@{
BoundaryId = 1677726
BoundaryType = 4
DisplayName = 'VPN 1'
Value = 'Auto:On'
}
)

$boundaryIPv6Return = @(
@{
BoundaryId = 1677726
BoundaryType = 2
DisplayName = 'IPv6 1'
Value = '2001:0DB8:0000:000b'
}
)

$boundarySubnetReturn = @(
@{
BoundaryId = 1677726
Expand Down Expand Up @@ -191,6 +223,32 @@ try
$result.BoundaryId | Should -Be -ExpectedValue '1677726'
}

It 'Should return desired result for Vpn return' {
Mock -CommandName Get-CMBoundary -MockWith { $boundaryVpnReturn }

$result = Get-TargetResource @inputVpnPresent
$result | Should -BeOfType System.Collections.HashTable
$result.SiteCode | Should -Be -ExpectedValue 'Lab'
$result.DisplayName | Should -Be -ExpectedValue 'VPN 1'
$result.Value | Should -Be -ExpectedValue 'Auto:On'
$result.Type | Should -Be -ExpectedValue 'VPN'
$result.Ensure | Should -Be -ExpectedValue 'Present'
$result.BoundaryId | Should -Be -ExpectedValue '1677726'
}

It 'Should return desired result for IPv6 return' {
Mock -CommandName Get-CMBoundary -MockWith { $boundaryIPv6Return }

$result = Get-TargetResource @inputIPv6Present
$result | Should -BeOfType System.Collections.HashTable
$result.SiteCode | Should -Be -ExpectedValue 'Lab'
$result.DisplayName | Should -Be -ExpectedValue 'IPv6 1'
$result.Value | Should -Be -ExpectedValue '2001:0DB8:0000:000b'
$result.Type | Should -Be -ExpectedValue 'IPv6Prefix'
$result.Ensure | Should -Be -ExpectedValue 'Present'
$result.BoundaryId | Should -Be -ExpectedValue '1677726'
}

It 'Should return desired result when boundary not found' {
Mock -CommandName Get-CMBoundary -MockWith { $null }

Expand Down
9 changes: 8 additions & 1 deletion tests/Unit/ConfigMgrCBDsc.ResourceHelper.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ InModuleScope $script:subModuleName {
BoundaryType = 4
Value = 'Description:Virtual Adapter'
}
@{
BoundaryID = 16777235
BoundaryType = 2
Value = '2001:0DB8:0000:000b'
}
)
}

Expand All @@ -238,7 +243,7 @@ InModuleScope $script:subModuleName {

$result = ConvertTo-CimBoundaries -InputObject $inputObject
$result | Should -BeOfType '[Microsoft.Management.Infrastructure.CimInstance]'
$result.Count | Should -Be -ExpectedValue 4
$result.Count | Should -Be -ExpectedValue 5
$result[0].Value | Should -Be -ExpectedValue '10.1.1.1-10.1.1.255'
$result[0].Type | Should -Be -ExpectedValue 'IPRange'
$result[1].Value | Should -Be -ExpectedValue '10.1.2.0'
Expand All @@ -247,6 +252,8 @@ InModuleScope $script:subModuleName {
$result[2].Type | Should -Be -ExpectedValue 'ADSite'
$result[3].Value | Should -Be -ExpectedValue 'Description:Virtual Adapter'
$result[3].Type | Should -Be -ExpectedValue 'VPN'
$result[4].Value | Should -Be -ExpectedValue '2001:0DB8:0000:000b'
$result[4].Type | Should -Be -ExpectedValue 'IPv6Prefix'
}
}
}
Expand Down

0 comments on commit f1cd564

Please sign in to comment.