Skip to content

Commit

Permalink
Merge pull request #2 from Sidoran/PR-Bugfixes
Browse files Browse the repository at this point in the history
fixes for the dsccommunity#1915
  • Loading branch information
Sidoran authored Apr 26, 2023
2 parents 176b7a0 + dfa16e8 commit 2cbb909
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
This parameter can only be used together with the module _SqlServer_ installed
(tested v21.0.17099). The parameter will be ignored if SQLPS module will be
used.
>>>>>>> upstream/main

## [16.2.0] - 2023-04-10

Expand Down
31 changes: 16 additions & 15 deletions source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ function Get-TargetResource
# Connect to the instance
$serverObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName -ErrorAction 'Stop'

# Get SQL module name
$sqlModuleName = (Get-Module -FullyQualifiedName (Get-SqlDscPreferredModule -ErrorAction 'Stop') -ListAvailable).Name

# Define current version for check compatibility
$sqlMajorVersion = $serverObject.Version.Major

Expand Down Expand Up @@ -96,10 +93,16 @@ function Get-TargetResource
$alwaysOnAvailabilityGroupResource.Add('BasicAvailabilityGroup', $availabilityGroup.BasicAvailabilityGroup)
$alwaysOnAvailabilityGroupResource.Add('DatabaseHealthTrigger', $availabilityGroup.DatabaseHealthTrigger)
$alwaysOnAvailabilityGroupResource.Add('DtcSupportEnabled', $availabilityGroup.DtcSupportEnabled)
if ( $sqlModuleName -eq 'SQLServer' )
# Microsoft.SqlServer.Management.Smo.Server from Connect-SQL supports the SeedingMode for SQL 2016 and higher, but New-SqlAvailabilityReplica may not.
# Will setting SeedingMode as $null to match ability of Microsoft.SqlServer.Management.Smo.Server and New-SqlAvailabilityReplica
if ( (Get-Command -Name 'New-SqlAvailabilityReplica').Parameters.ContainsKey('SeedingMode') )
{
$alwaysOnAvailabilityGroupResource.Add('SeedingMode', $availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName].SeedingMode)
}
else
{
$alwaysOnAvailabilityGroupResource.Add('SeedingMode', $null)
}
}
}

Expand Down Expand Up @@ -262,9 +265,6 @@ function Set-TargetResource
# Connect to the instance
$serverObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName -ErrorAction 'Stop'

# Get SQL module name
$sqlModuleName = (Get-Module -FullyQualifiedName (Get-SqlDscPreferredModule -ErrorAction 'Stop') -ListAvailable).Name

# Determine if HADR is enabled on the instance. If not, throw an error
if ( -not $serverObject.IsHadrEnabled )
{
Expand Down Expand Up @@ -356,7 +356,7 @@ function Set-TargetResource
$newReplicaParams.Add('ConnectionModeInSecondaryRole', $ConnectionModeInSecondaryRole)
}

if ( ( $sqlMajorVersion -ge 13 ) -and ( $sqlModuleName -eq 'SQLServer' ) )
if ( ( $sqlMajorVersion -ge 13 ) -and (Get-Command -Name 'New-SqlAvailabilityReplica').Parameters.ContainsKey('SeedingMode') )
{
$newReplicaParams.Add('SeedingMode', $SeedingMode)
}
Expand Down Expand Up @@ -521,10 +521,13 @@ function Set-TargetResource
Update-AvailabilityGroup -AvailabilityGroup $availabilityGroup
}

if ( ( $submittedParameters -contains 'SeedingMode' ) -and ( $sqlMajorVersion -ge 13 ) -and ( $SeedingMode -ne $availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName].SeedingMode ) -and ( $sqlModuleName -eq 'SQLServer' ) )
if ( ( $submittedParameters -contains 'SeedingMode' ) -and ( $sqlMajorVersion -ge 13 ) -and ( $SeedingMode -ne $availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName].SeedingMode ) )
{
$availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName].SeedingMode = $SeedingMode
Update-AvailabilityGroupReplica -AvailabilityGroupReplica $availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName]
if ( (Get-Command -Name 'New-SqlAvailabilityReplica').Parameters.ContainsKey('SeedingMode') )
{
$availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName].SeedingMode = $SeedingMode
Update-AvailabilityGroupReplica -AvailabilityGroupReplica $availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName]
}
}
}
}
Expand Down Expand Up @@ -710,9 +713,6 @@ function Test-TargetResource
# Define current version for check compatibility
$sqlMajorVersion = $getTargetResourceResult.Version

# Get SQL module name
$sqlModuleName = (Get-Module -FullyQualifiedName (Get-SqlDscPreferredModule -ErrorAction 'Stop') -ListAvailable).Name

switch ($Ensure)
{
'Absent'
Expand Down Expand Up @@ -747,12 +747,13 @@ function Test-TargetResource
<#
Add properties compatible with SQL Server 2016 or later versions
DtcSupportEnabled is enabled at the creation of the Availability Group only, hence it will not be checked in this block
SeedingMode should be checked only in case if New-SqlAvailabilityReplica support the SeedingMode parameter
#>
if ( $sqlMajorVersion -ge 13 )
{
$parametersToCheck += 'BasicAvailabilityGroup'
$parametersToCheck += 'DatabaseHealthTrigger'
if ( $sqlModuleName -eq 'SQLServer' )
if ( $getTargetResourceResult.SeedingMode )
{
$parametersToCheck += 'SeedingMode'
}
Expand Down
30 changes: 17 additions & 13 deletions source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ function Get-TargetResource
# Define current version for check compatibility
$sqlMajorVersion = $serverObject.Version.Major

# Get SQL module name
$sqlModuleName = (Get-Module -FullyQualifiedName (Get-SqlDscPreferredModule -ErrorAction 'Stop') -ListAvailable).Name

# Is this node actively hosting the SQL instance?
$isActiveNode = Test-ActiveNode -ServerObject $serverObject

Expand Down Expand Up @@ -89,7 +86,7 @@ function Get-TargetResource
EndpointHostName = $serverObject.NetName
}

if ( ( $sqlMajorVersion -ge 13 ) -and ( $sqlModuleName -eq 'SQLServer' ) )
if ( ( $sqlMajorVersion -ge 13 ) )
{
$alwaysOnAvailabilityGroupReplicaResource.Add('SeedingMode', '')
}
Expand All @@ -115,9 +112,16 @@ function Get-TargetResource
$alwaysOnAvailabilityGroupReplicaResource.ReadOnlyRoutingConnectionUrl = $availabilityGroupReplica.ReadOnlyRoutingConnectionUrl
$alwaysOnAvailabilityGroupReplicaResource.ReadOnlyRoutingList = $availabilityGroupReplica.ReadOnlyRoutingList

if ( ( $sqlMajorVersion -ge 13 ) -and ( $sqlModuleName -eq 'SQLServer' ) )
if ( $sqlMajorVersion -ge 13 )
{
$alwaysOnAvailabilityGroupReplicaResource.'SeedingMode' = $availabilityGroupReplica.SeedingMode
if ( (Get-Command -Name 'New-SqlAvailabilityReplica').Parameters.ContainsKey('SeedingMode') )
{
$alwaysOnAvailabilityGroupReplicaResource.'SeedingMode' = $availabilityGroupReplica.SeedingMode
}
else
{
$alwaysOnAvailabilityGroupReplicaResource.'SeedingMode' = $null
}
}
}
}
Expand Down Expand Up @@ -272,9 +276,6 @@ function Set-TargetResource
# Define current version for check compatibility
$sqlMajorVersion = $serverObject.Version.Major

# Get SQL module name
$sqlModuleName = (Get-Module -FullyQualifiedName (Get-SqlDscPreferredModule -ErrorAction 'Stop') -ListAvailable).Name

# Determine if HADR is enabled on the instance. If not, throw an error
if ( -not $serverObject.IsHadrEnabled )
{
Expand Down Expand Up @@ -428,10 +429,13 @@ function Set-TargetResource
$availabilityGroupReplicaUpdatesRequired = $true
}

if ( ( $submittedParameters -contains 'SeedingMode' ) -and ( $sqlMajorVersion -ge 13 ) -and ( $SeedingMode -ne $availabilityGroupReplica.SeedingMode ) -and ( $sqlModuleName -eq 'SQLServer' ) )
if ( ( $submittedParameters -contains 'SeedingMode' ) -and ( $sqlMajorVersion -ge 13 ) -and ( $SeedingMode -ne $availabilityGroupReplica.SeedingMode ) )
{
$availabilityGroupReplica.SeedingMode = $SeedingMode
$availabilityGroupReplicaUpdatesRequired = $true
if ((Get-Command -Name 'New-SqlAvailabilityReplica').Parameters.ContainsKey('SeedingMode'))
{
$availabilityGroupReplica.SeedingMode = $SeedingMode
$availabilityGroupReplicaUpdatesRequired = $true
}
}

if ( $availabilityGroupReplicaUpdatesRequired )
Expand Down Expand Up @@ -495,7 +499,7 @@ function Set-TargetResource
$newAvailabilityGroupReplicaParams.Add('ReadOnlyRoutingList', $ReadOnlyRoutingList)
}

if ( ( $sqlMajorVersion -ge 13 ) -and ( $sqlModuleName -eq 'SQLServer' ) )
if ( ( $sqlMajorVersion -ge 13 ) -and (Get-Command -Name 'New-SqlAvailabilityReplica').Parameters.ContainsKey('SeedingMode') )
{
$newAvailabilityGroupReplicaParams.Add('SeedingMode', $SeedingMode)
}
Expand Down

0 comments on commit 2cbb909

Please sign in to comment.