diff --git a/CHANGELOG.md b/CHANGELOG.md index 12f3bc14c..13d57f09b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,10 +18,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - New public command: - `Get-SqlDscPreferredModule` - Returns the name of the first available preferred module ([issue #1879](https://github.com/dsccommunity/SqlServerDsc/issues/1879)). -- `SqlSecureConnection` +- SqlSecureConnection - Added new parameter `ServerName` that will be used as the host name when restarting the SQL Server instance. The specified value should be the same name that is used in the certificate ([issue #1888](https://github.com/dsccommunity/SqlServerDsc/issues/1888)). +- SqlSetup + - Added new parameter `ServerName` that will be used as the host name when + evaluating the SQL Server instance. If using a secure connection the + specified value should be the same name that is used in the certificate + ([issue #1893](https://github.com/dsccommunity/SqlServerDsc/issues/1893)). ### Changed diff --git a/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 b/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 index f31248cba..ea1b68e6c 100644 --- a/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 +++ b/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 @@ -45,6 +45,13 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' Specifies to install the English version of SQL Server on a localized operating system when the installation media includes language packs for both English and the language corresponding to the operating system. + + .PARAMETER ServerName + Specifies the host or network name of the _SQL Server_ instance. If the + SQL Server belongs to a cluster or availability group it could be set to + the host name for the listener or cluster group. If using a secure connection + the specified value should be the same name that is used in the certificate. + Default value is the current computer name. #> function Get-TargetResource { @@ -85,7 +92,11 @@ function Get-TargetResource [Parameter()] [System.Boolean] - $UseEnglish + $UseEnglish, + + [Parameter()] + [System.String] + $ServerName ) if ($FeatureFlag) @@ -144,6 +155,7 @@ function Get-TargetResource FailoverClusterGroupName = $null FailoverClusterIPAddress = $null UseEnglish = $UseEnglish + ServerName = $ServerName } <# @@ -156,7 +168,14 @@ function Get-TargetResource } else { - $sqlHostName = Get-ComputerName + if ($PSBoundParameters.ContainsKey('ServerName')) + { + $sqlHostName = $ServerName + } + else + { + $sqlHostName = Get-ComputerName + } } # Force drive list update, to pick up any newly mounted volumes @@ -642,6 +661,13 @@ function Get-TargetResource .PARAMETER SkipRule Specifies optional skip rules during setup. + + .PARAMETER ServerName + Specifies the host or network name of the _SQL Server_ instance. If the + SQL Server belongs to a cluster or availability group it could be set to + the host name for the listener or cluster group. If using a secure connection + the specified value should be the same name that is used in the certificate. + Default value is the current computer name. #> function Set-TargetResource { @@ -903,7 +929,11 @@ function Set-TargetResource [Parameter()] [ValidateNotNullOrEmpty()] [System.String[]] - $SkipRule + $SkipRule, + + [Parameter()] + [System.String] + $ServerName ) <# @@ -927,6 +957,11 @@ function Set-TargetResource FeatureFlag = $FeatureFlag } + if ($PSBoundParameters.ContainsKey('ServerName')) + { + $getTargetResourceParameters.ServerName = $ServerName + } + $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters $InstanceName = $InstanceName.ToUpper() @@ -1854,6 +1889,13 @@ function Set-TargetResource Specifies optional skip rules during setup. Not used in Test-TargetResource. + + .PARAMETER ServerName + Specifies the host or network name of the _SQL Server_ instance. If the + SQL Server belongs to a cluster or availability group it could be set to + the host name for the listener or cluster group. If using a secure connection + the specified value should be the same name that is used in the certificate. + Default value is the current computer name. #> function Test-TargetResource { @@ -2115,7 +2157,11 @@ function Test-TargetResource [Parameter()] [ValidateNotNullOrEmpty()] [System.String[]] - $SkipRule + $SkipRule, + + [Parameter()] + [System.String] + $ServerName ) <# @@ -2136,9 +2182,13 @@ function Test-TargetResource FeatureFlag = $FeatureFlag } - $boundParameters = $PSBoundParameters + if ($PSBoundParameters.ContainsKey('ServerName')) + { + $getTargetResourceParameters.ServerName = $ServerName + } $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters + if ($null -eq $getTargetResourceResult.Features -or $getTargetResourceResult.Features -eq '') { Write-Verbose -Message $script:localizedData.NoFeaturesFound @@ -2160,6 +2210,7 @@ function Test-TargetResource if ($feature -notin $foundFeaturesArray) { Write-Verbose -Message ($script:localizedData.UnableToFindFeature -f $feature, $($getTargetResourceResult.Features)) + $result = $false } } @@ -2173,14 +2224,15 @@ function Test-TargetResource { Write-Verbose -Message $script:localizedData.EvaluatingClusterParameters - $variableNames = $boundParameters.Keys | + $variableNames = $PSBoundParameters.Keys | Where-Object -FilterScript { $_ -imatch "^FailoverCluster" } foreach ($variableName in $variableNames) { - if ($getTargetResourceResult.$variableName -ne $boundParameters[$variableName]) + if ($getTargetResourceResult.$variableName -ne $PSBoundParameters.$variableName) { - Write-Verbose -Message ($script:localizedData.ClusterParameterIsNotInDesiredState -f $variableName, $($boundParameters[$variableName])) + Write-Verbose -Message ($script:localizedData.ClusterParameterIsNotInDesiredState -f $variableName, ($PSBoundParameters.$variableName)) + $result = $false } } diff --git a/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.schema.mof b/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.schema.mof index 3580cdeec..88da6425f 100644 --- a/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.schema.mof +++ b/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.schema.mof @@ -68,5 +68,6 @@ class DSC_SqlSetup : OMI_BaseResource [Write, Description("Feature flags are used to toggle DSC resource functionality on or off. See the DSC resource documentation for what additional functionality exist through a feature flag.")] String FeatureFlag[]; [Write, Description("Specifies to install the English version of _SQL Server_ on a localized operating system when the installation media includes language packs for both English and the language corresponding to the operating system.")] Boolean UseEnglish; [Write, Description("Specifies optional skip rules during setup.")] String SkipRule[]; + [Write, Description("Specifies the host or network name of the _SQL Server_ instance. If the SQL Server belongs to a cluster or availability group it could be set to the host name for the listener or cluster group. If using a secure connection the specified value should be the same name that is used in the certificate. Default value is the current computer name.")] String ServerName; [Read, Description("Returns a boolean value of `$true` if the instance is clustered, otherwise it returns `$false`.")] Boolean IsClustered; }; diff --git a/tests/Unit/DSC_SqlSetup.Tests.ps1 b/tests/Unit/DSC_SqlSetup.Tests.ps1 index 1b3ba05aa..51ad17162 100644 --- a/tests/Unit/DSC_SqlSetup.Tests.ps1 +++ b/tests/Unit/DSC_SqlSetup.Tests.ps1 @@ -311,6 +311,7 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { SourceCredential = $null SourcePath = $TestDrive Feature = 'NewFeature' # Test enabling a code-feature. + ServerName = 'host.company.local' } } } @@ -376,6 +377,7 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result.ASConfigDir | Should -BeNullOrEmpty $result.ASServerMode | Should -BeNullOrEmpty $result.ISSvcAccountUsername | Should -BeNullOrEmpty + $result.ServerName | Should -Be 'host.company.local' } } } @@ -1734,6 +1736,7 @@ Describe 'SqlSetup\Test-TargetResource' -Tag 'Test' { $mockTestTargetResourceParameters.InstanceName = 'MSSQLSERVER' $mockTestTargetResourceParameters.SourceCredential = $null $mockTestTargetResourceParameters.SourcePath = $TestDrive + $mockTestTargetResourceParameters.ServerName = 'host.company.local' $result = Test-TargetResource @mockTestTargetResourceParameters @@ -2300,6 +2303,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SourcePath = $TestDrive ProductKey = '1FAKE-2FAKE-3FAKE-4FAKE-5FAKE' NpEnabled = $true + ServerName = 'host.company.local' } { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw