diff --git a/CHANGELOG.md b/CHANGELOG.md index ad17ae15..5427d9cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md) ## [Unreleased] +- ClusterQuorum + - New parameter Endpoint to support Azure Government cloud. Default value now is only for the commercial one. + ### Changed - FailoverClusterDsc diff --git a/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 b/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 index 80e8109c..bd292914 100644 --- a/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 +++ b/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 @@ -94,6 +94,9 @@ function Get-TargetResource $clusterQuorumResource = $getClusterQuorumResult.QuorumResource | Get-ClusterParameter -Name AccountName | Select-Object -ExpandProperty Value + $clusterQuorumEndpoint = $getClusterQuorumResult.QuorumResource | + Get-ClusterParameter -Name EndpointInfo | + Select-Object -ExpandProperty Value } else { @@ -104,6 +107,7 @@ function Get-TargetResource IsSingleInstance = $IsSingleInstance Type = $clusterQuorumType Resource = $clusterQuorumResource + Endpoint = $clusterQuorumEndpoint StorageAccountAccessKey = "" # Return an empty value since we cannot retrieve the current Access Key } } @@ -123,6 +127,10 @@ function Get-TargetResource The name of the disk, file share or Azure storage account resource to use as witness. This parameter is optional if the quorum type is set to NodeMajority. + .PARAMETER Endpoint + Azure service endpoint. This paramter is required if the quorum type is set to NodeAndCloudMajority. + The default value is core.windows.net and only need to override when using Azure Government Cloud (eg: core.usgovcloudapi.net) + .PARAMETER StorageAccountAccessKey The access key of the Azure storage account to use as witness. This parameter is required if the quorum type is set to NodeAndCloudMajority. @@ -147,6 +155,10 @@ function Set-TargetResource [System.String] $Resource, + [Parameter()] + [System.String] + $Endpoint, + [Parameter()] [System.String] $StorageAccountAccessKey @@ -178,7 +190,7 @@ function Set-TargetResource 'NodeAndCloudMajority' { - Set-ClusterQuorum -CloudWitness -AccountName $Resource -AccessKey $StorageAccountAccessKey + Set-ClusterQuorum -CloudWitness -AccountName $Resource -AccessKey $StorageAccountAccessKey -Endpoint $Endpoint } } } @@ -198,6 +210,10 @@ function Set-TargetResource The name of the disk, file share or Azure storage account resource to use as witness. This parameter is optional if the quorum type is set to NodeMajority. + .PARAMETER Endpoint + Azure service endpoint. This paramter is required if the quorum type is set to NodeAndCloudMajority. + The default value is core.windows.net and only need to override when using Azure Government Cloud (eg: core.usgovcloudapi.net) + .PARAMETER StorageAccountAccessKey The access key of the Azure storage account to use as witness. This parameter is required if the quorum type is set to NodeAndCloudMajority. @@ -224,6 +240,10 @@ function Test-TargetResource [System.String] $Resource, + [Parameter()] + [System.String] + $Endpoint, + [Parameter()] [System.String] $StorageAccountAccessKey @@ -233,11 +253,21 @@ function Test-TargetResource $getGetTargetResourceResult = Get-TargetResource -IsSingleInstance $IsSingleInstance - $testTargetResourceReturnValue = $false + $testTargetResourceReturnValue = $true + + if ($getGetTargetResourceResult.Type -ne $Type) + { + $testTargetResourceReturnValue = $false + } + + if ($PSBoundParameters.ContainsKey('Resource') -and $getGetTargetResourceResult.Resource -ne $Resource) + { + $testTargetResourceReturnValue = $false + } - if ($getGetTargetResourceResult.Type -eq $Type -and $getGetTargetResourceResult.Resource -eq $Resource) + if ($PSBoundParameters.ContainsKey('Endpoint') -and $getGetTargetResourceResult.Endpoint -ne $Endpoint) { - $testTargetResourceReturnValue = $true + $testTargetResourceReturnValue = $false } $testTargetResourceReturnValue diff --git a/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.schema.mof b/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.schema.mof index b903cf06..ffe25632 100644 --- a/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.schema.mof +++ b/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.schema.mof @@ -4,5 +4,6 @@ class DSC_ClusterQuorum : OMI_BaseResource [Key, Description("Specifies the resource is a single instance, the value must be `'Yes'`."), ValueMap{"Yes"}, Values{"Yes"}] string IsSingleInstance; [Write, Description("Quorum type to use."), ValueMap{"NodeMajority", "NodeAndDiskMajority", "NodeAndFileShareMajority", "NodeAndCloudMajority", "DiskOnly"}, Values{"NodeMajority", "NodeAndDiskMajority", "NodeAndFileShareMajority", "NodeAndCloudMajority", "DiskOnly"}] string Type; [Write, Description("The name of the disk, file share or Azure storage account resource to use as witness. This parameter is optional if the quorum type is set to `'NodeMajority'`.")] String Resource; + [Write, Description("Azure service endpoint. This parameter is required if the quorum type is set to `'NodeAndCloudMajority'`.")] String Endpoint; [Write, Description("The access key of the Azure storage account to use as witness. This parameter is required if the quorum type is set to `'NodeAndCloudMajority'`. **NOTE!** The key is currently not updated if the resource is already set.")] String StorageAccountAccessKey; }; diff --git a/tests/Unit/DSC_ClusterQuorum.Tests.ps1 b/tests/Unit/DSC_ClusterQuorum.Tests.ps1 index 8ae455e6..c825ee76 100644 --- a/tests/Unit/DSC_ClusterQuorum.Tests.ps1 +++ b/tests/Unit/DSC_ClusterQuorum.Tests.ps1 @@ -56,6 +56,7 @@ foreach ($moduleVersion in @('2012', '2016')) $mockQuorumFileShareWitnessPath = '\\FILE01\CLUSTER01' $mockQuorumAccountName = 'AccountName' $mockQuorumAccessKey = 'USRuD354YbOHkPI35SUVyMj2W3odWekMIEdj3n2qAbc0yzqwpMwH-+M+GHJ27OuA5FkTxsbBF9qGc6r6UM3ipg==' + $mockQuorumAccountEndpoint = 'endpoint.azure.dummy' $mockGetClusterQuorum = { $getClusterQuorumReturnValue = [PSCustomObject] @{ @@ -162,6 +163,7 @@ foreach ($moduleVersion in @('2012', '2016')) $CloudWitness -eq $true ` -and $AccountName -eq $mockQuorumAccountName ` -and $AccessKey -eq $mockQuorumAccessKey + # -and $Endpoint -eq $mockQuorumAccountEndpoint } $mockDefaultParameters = @{ @@ -173,7 +175,18 @@ foreach ($moduleVersion in @('2012', '2016')) Mock -CommandName 'Get-ClusterQuorum' -MockWith $mockGetClusterQuorum Mock -CommandName 'Get-ClusterParameter' -MockWith $mockGetClusterParameter_SharePath -ParameterFilter $mockGetClusterParameter_SharePath_ParameterFilter Mock -CommandName 'Get-ClusterParameter' -MockWith $mockGetClusterParameter_AccountName -ParameterFilter $mockGetClusterParameter_AccountName_ParameterFilter - + Mock -CommandName 'Get-ClusterParameter' -MockWith { + return @( + [PSCustomObject] @{ + Object = 'Cloud Witness' + Name = 'EndpointInfo' + Type = 'String' + Value = 'endpoint.azure.dummy' + } + ) + } -ParameterFilter { + $Name -eq 'EndpointInfo' + } $mockTestParameters = $mockDefaultParameters.Clone() } @@ -315,6 +328,7 @@ foreach ($moduleVersion in @('2012', '2016')) $getTargetResourceResult = Get-TargetResource @mockTestParameters $getTargetResourceResult.Type | Should -Be $mockQuorumType_NodeAndCloudMajority $getTargetResourceResult.Resource | Should -Be $mockQuorumAccountName + $getTargetResourceResult.Endpoint | Should -Be $mockQuorumAccountEndpoint } } } @@ -366,7 +380,19 @@ foreach ($moduleVersion in @('2012', '2016')) Mock -CommandName 'Get-ClusterQuorum' -MockWith $mockGetClusterQuorum Mock -CommandName 'Get-ClusterParameter' -MockWith $mockGetClusterParameter_SharePath -ParameterFilter $mockGetClusterParameter_SharePath_ParameterFilter Mock -CommandName 'Get-ClusterParameter' -MockWith $mockGetClusterParameter_AccountName -ParameterFilter $mockGetClusterParameter_AccountName_ParameterFilter - + Mock -CommandName 'Get-ClusterParameter' -MockWith { + return @( + [PSCustomObject] @{ + Object = 'Cloud Witness' + Name = 'EndpointInfo' + Type = 'String' + Value = 'endpoint.azure.dummy' + } + ) + } -ParameterFilter { + $Name -eq 'EndpointInfo' + } + $mockTestParameters = $mockDefaultParameters.Clone() } @@ -495,6 +521,7 @@ foreach ($moduleVersion in @('2012', '2016')) $mockTestParameters['Type'] = $mockQuorumType_NodeAndCloudMajority $mockTestParameters['Resource'] = $mockQuorumAccountName + $mockTestParameters['Endpoint'] = $mockQuorumAccountEndpoint $mockTestParameters['StorageAccountAccessKey'] = $mockQuorumAccessKey } @@ -634,7 +661,7 @@ foreach ($moduleVersion in @('2012', '2016')) $mockTestParameters['Type'] = $mockQuorumType_NodeAndCloudMajority $mockTestParameters['Resource'] = $mockQuorumAccountName $mockTestParameters['StorageAccountAccessKey'] = $mockQuorumAccessKey - + $mockTestParameters['Endpoint'] = $mockQuorumAccountEndpoint $mockDynamicQuorumResourceName = $mockQuorumAccountName }