14
14
15
15
function Test-AccountRelatedCmdlets
16
16
{
17
- $rgName = " CosmosDBResourceGroup3 "
17
+ $rgName = " CosmosDBResourceGroup89 "
18
18
$location = " East US"
19
19
$locationlist = " East US" , " West US"
20
20
$locationlist2 = " East US" , " UK South" , " UK West" , " South India"
21
21
$locationlist3 = " West US" , " East US"
22
22
23
23
$resourceGroup = New-AzResourceGroup - ResourceGroupName $rgName - Location $location
24
24
25
- $cosmosDBAccountName = " cosmosdb671 "
25
+ $cosmosDBAccountName = " cosmosdb67 "
26
26
27
27
# use an existing account with the following information for Account Update Operations
28
28
$cosmosDBExistingAccountName = " dbaccount27"
29
29
$existingResourceGroupName = " CosmosDBResourceGroup27"
30
30
31
- $ipRangeFilter = " 192 .168.0 .1"
31
+ $IpRule = " 201 .168.50 .1"
32
32
$tags = @ { name = " test" ; Shape = " Square" ; Color = " Blue" }
33
33
$publicNetworkAccess = " Enabled"
34
34
35
- $cosmosDBAccount = New-AzCosmosDBAccount - ResourceGroupName $rgName - Name $cosmosDBAccountName - DefaultConsistencyLevel " BoundedStaleness" - MaxStalenessIntervalInSeconds 10 - MaxStalenessPrefix 20 - Location $location - IpRangeFilter $ipRangeFilter - Tag $tags - EnableVirtualNetwork - EnableMultipleWriteLocations - EnableAutomaticFailover - ApiKind " MongoDB" - PublicNetworkAccess $publicNetworkAccess
36
- do
37
- {
38
- $cosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $rgName - Name $cosmosDBAccountName
39
- } while ($cosmosDBAccount.ProvisioningState -ne " Succeeded" )
35
+ $cosmosDBAccount = New-AzCosmosDBAccount - ResourceGroupName $rgName - Name $cosmosDBAccountName - DefaultConsistencyLevel " BoundedStaleness" - MaxStalenessIntervalInSeconds 10 - MaxStalenessPrefix 20 - Location $location - IpRule $IpRule - Tag $tags - EnableVirtualNetwork - EnableMultipleWriteLocations - EnableAutomaticFailover - ApiKind " MongoDB" - PublicNetworkAccess $publicNetworkAccess - EnableFreeTier 0 - EnableAnalyticalStorage 0 - ServerVersion " 3.2"
40
36
41
37
Assert-AreEqual $cosmosDBAccountName $cosmosDBAccount.Name
42
38
Assert-AreEqual " BoundedStaleness" $cosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
43
39
Assert-AreEqual 10 $cosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
44
40
Assert-AreEqual 20 $cosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
45
- Assert-AreEqual $ipRangeFilter $cosmosDBAccount.IpRangeFilter
46
41
Assert-AreEqual $cosmosDBAccount.EnableAutomaticFailover 1
47
42
Assert-AreEqual $cosmosDBAccount.EnableMultipleWriteLocations 1
48
43
Assert-AreEqual $cosmosDBAccount.IsVirtualNetworkFilterEnabled 1
49
44
Assert-AreEqual $cosmosDBAccount.PublicNetworkAccess $publicNetworkAccess
45
+ Assert-AreEqual $cosmosDBAccount.ApiProperties.ServerVersion " 3.2"
46
+ Assert-AreEqual $cosmosDBAccount.EnableAnalyticalStorage 0
47
+ Assert-AreEqual $cosmosDBAccount.EnableFreeTier 0
50
48
51
- $updatedCosmosDBAccount = Update-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName - DefaultConsistencyLevel " BoundedStaleness" - MaxStalenessIntervalInSeconds 10 - MaxStalenessPrefix 20 - IpRangeFilter $ipRangeFilter - Tag $tags - EnableVirtualNetwork 1 - EnableAutomaticFailover 1 - PublicNetworkAccess $publicNetworkAccess
52
- do
53
- {
54
- $updatedCosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName
55
- } while ($cosmosDBAccount.ProvisioningState -ne " Succeeded" )
49
+ $updatedCosmosDBAccount = Update-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName - DefaultConsistencyLevel " BoundedStaleness" - MaxStalenessIntervalInSeconds 10 - MaxStalenessPrefix 20 - IpRule $IpRule - Tag $tags - EnableVirtualNetwork 1 - EnableAutomaticFailover 1 - PublicNetworkAccess $publicNetworkAccess
56
50
57
51
Assert-AreEqual $cosmosDBExistingAccountName $updatedCosmosDBAccount.Name
58
52
Assert-AreEqual " BoundedStaleness" $updatedCosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
59
53
Assert-AreEqual 10 $updatedCosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
60
54
Assert-AreEqual 20 $updatedCosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
61
- Assert-AreEqual $ipRangeFilter $updatedCosmosDBAccount.IpRangeFilter
62
55
Assert-AreEqual $updatedCosmosDBAccount.EnableAutomaticFailover 1
63
56
Assert-AreEqual $updatedCosmosDBAccount.IsVirtualNetworkFilterEnabled 1
64
57
Assert-AreEqual $updatedCosmosDBAccount.PublicNetworkAccess $publicNetworkAccess
@@ -88,7 +81,7 @@ function Test-AccountRelatedCmdletsUsingRid
88
81
$cosmosDBExistingAccountName = " dbaccount27"
89
82
$existingResourceGroupName = " CosmosDBResourceGroup27"
90
83
91
- $ipRangeFilter = " 192 .168.0 .1"
84
+ $IpRule = " 201 .168.50 .1"
92
85
$tags = @ { name = " test" ; Shape = " Square" ; Color = " Blue" }
93
86
94
87
$cosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName
@@ -98,12 +91,11 @@ function Test-AccountRelatedCmdletsUsingRid
98
91
Assert-AreEqual $cosmosDBAccountByRid.ConsistencyPolicy.DefaultConsistencyLevel $cosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
99
92
Assert-AreEqual $cosmosDBAccountByRid.ConsistencyPolicy.MaxIntervalInSeconds $cosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
100
93
Assert-AreEqual $cosmosDBAccountByRid.ConsistencyPolicy.MaxStalenessPrefix $cosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
101
- Assert-AreEqual $cosmosDBAccountByRid.IpRangeFilter $cosmosDBAccount.IpRangeFilter
102
94
Assert-AreEqual $cosmosDBAccountByRid.EnableAutomaticFailover $cosmosDBAccount.EnableAutomaticFailover
103
95
Assert-AreEqual $cosmosDBAccountByRid.EnableMultipleWriteLocations $cosmosDBAccount.EnableMultipleWriteLocations
104
96
Assert-AreEqual $cosmosDBAccountByRid.IsVirtualNetworkFilterEnabled $cosmosDBAccount.IsVirtualNetworkFilterEnabled
105
97
106
- $updatedCosmosDBAccount = Update-AzCosmosDBAccount - ResourceId $cosmosDBAccount.Id - DefaultConsistencyLevel " BoundedStaleness" - MaxStalenessIntervalInSeconds 10 - MaxStalenessPrefix 20 - IpRangeFilter $ipRangeFilter - Tag $tags - EnableVirtualNetwork 1 - EnableAutomaticFailover 1
98
+ $updatedCosmosDBAccount = Update-AzCosmosDBAccount - ResourceId $cosmosDBAccount.Id - DefaultConsistencyLevel " BoundedStaleness" - MaxStalenessIntervalInSeconds 10 - MaxStalenessPrefix 20 - IpRule $IpRule - Tag $tags - EnableVirtualNetwork 1 - EnableAutomaticFailover 1
107
99
do
108
100
{
109
101
$updatedCosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName
@@ -113,7 +105,6 @@ function Test-AccountRelatedCmdletsUsingRid
113
105
Assert-AreEqual " BoundedStaleness" $updatedCosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
114
106
Assert-AreEqual 10 $updatedCosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
115
107
Assert-AreEqual 20 $updatedCosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
116
- Assert-AreEqual $ipRangeFilter $updatedCosmosDBAccount.IpRangeFilter
117
108
Assert-AreEqual $updatedCosmosDBAccount.EnableAutomaticFailover 1
118
109
Assert-AreEqual $updatedCosmosDBAccount.IsVirtualNetworkFilterEnabled 1
119
110
@@ -136,12 +127,12 @@ function Test-AccountRelatedCmdletsUsingObject
136
127
$cosmosDBExistingAccountName = " dbaccount27"
137
128
$existingResourceGroupName = " CosmosDBResourceGroup27"
138
129
139
- $ipRangeFilter = " 192 .168.0 .1"
130
+ $IpRule = " 201 .168.50 .1"
140
131
$tags = @ { name = " test" ; Shape = " Square" ; Color = " Blue" }
141
132
142
133
$cosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName
143
134
144
- $updatedCosmosDBAccount = Update-AzCosmosDBAccount - InputObject $cosmosDBAccount - DefaultConsistencyLevel " BoundedStaleness" - MaxStalenessIntervalInSeconds 10 - MaxStalenessPrefix 20 - IpRangeFilter $ipRangeFilter - Tag $tags - EnableVirtualNetwork 1 - EnableAutomaticFailover 1
135
+ $updatedCosmosDBAccount = Update-AzCosmosDBAccount - InputObject $cosmosDBAccount - DefaultConsistencyLevel " BoundedStaleness" - MaxStalenessIntervalInSeconds 10 - MaxStalenessPrefix 20 - IpRule $IpRule - Tag $tags - EnableVirtualNetwork 1 - EnableAutomaticFailover 1
145
136
do
146
137
{
147
138
$updatedCosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName
@@ -151,7 +142,6 @@ function Test-AccountRelatedCmdletsUsingObject
151
142
Assert-AreEqual " BoundedStaleness" $updatedCosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
152
143
Assert-AreEqual 10 $updatedCosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
153
144
Assert-AreEqual 20 $updatedCosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
154
- Assert-AreEqual $ipRangeFilter $updatedCosmosDBAccount.IpRangeFilter
155
145
Assert-AreEqual $updatedCosmosDBAccount.EnableAutomaticFailover 1
156
146
Assert-AreEqual $updatedCosmosDBAccount.IsVirtualNetworkFilterEnabled 1
157
147
@@ -173,21 +163,27 @@ function Test-AccountRelatedCmdletsUsingObject
173
163
174
164
function Test-AddRegionOperation
175
165
{
176
- $rgName = " CosmosDBResourceGroup2 "
166
+ $rgName = " CosmosDBResourceGroup3 "
177
167
$location = " East US"
178
168
$locationlist = " East US" , " West US"
179
- $cosmosDBAccountName = " testupdateregion "
169
+ $cosmosDBAccountName = " testupdateregionpowershell2 "
180
170
$resourceGroup = New-AzResourceGroup - ResourceGroupName $rgName - Location $location
181
171
172
+ try {
182
173
$cosmosDBAccount = New-AzCosmosDBAccount - ResourceGroupName $rgName - Name $cosmosDBAccountName - Location $location - EnableMultipleWriteLocations - EnableAutomaticFailover
183
174
do
184
175
{
185
- $cosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $rgName - Name $cosmosDBAccountName
176
+ $cosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $rgName - Name $cosmosDBAccountName
186
177
} while ($cosmosDBAccount.ProvisioningState -ne " Succeeded" )
187
-
188
- $updatedCosmosDBAccount = Update-AzCosmosDBAccountRegion - ResourceGroupName $rgName - Name $cosmosDBAccountName - Location $locationlist
189
- $updatedCosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $rgName - Name $cosmosDBAccountName
190
- Assert-AreEqual $cosmosDBAccount.Locations.Count $updatedCosmosDBAccount.Locations.Count - 1
178
+
179
+ $updatedCosmosDBAccount = Update-AzCosmosDBAccountRegion - ResourceGroupName $rgName - Name $cosmosDBAccountName - Location $locationlist
180
+ $updatedCosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $rgName - Name $cosmosDBAccountName
181
+ Assert-AreEqual $cosmosDBAccount.Locations.Count $updatedCosmosDBAccount.Locations.Count - 1
182
+ }
183
+ finally {
184
+ # unable to delete account immediately after adding region
185
+ # Remove-AzCosmosDBAccount -ResourceGroupName $rgName -Name $cosmosDBAccountName
186
+ }
191
187
}
192
188
193
189
function Test-PrivateEndpoint
@@ -196,41 +192,47 @@ function Test-PrivateEndpoint
196
192
$location = " East US"
197
193
$peName = " mype" ;
198
194
$storageAccount = " xdmsa2" ;
195
+ $vnetName = " MyVnetPE"
199
196
200
- # use an existing account with the following properties
201
- $cosmosDBExistingAccountName = " db9934121"
197
+ $cosmosDBAccountName = " db945"
202
198
$rgname = " CosmosDBResourceGroup9507"
203
199
204
- $cosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $rgname - Name $cosmosDBExistingAccountName
205
- $resourceId = $cosmosDBAccount.Id
200
+ try {
201
+ $cosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $rgname - Name $cosmosDBAccountName
202
+ $resourceId = $cosmosDBAccount.Id
206
203
207
- $peSubnet = New-AzVirtualNetworkSubnetConfig - Name peSubnet - AddressPrefix " 11.0.1.0/24" - PrivateEndpointNetworkPolicies " Disabled"
208
- $vnetPE = New-AzVirtualNetwork - Name " vnetPE " - ResourceGroupName $rgname - Location $location - AddressPrefix " 11.0.0.0/16" - Subnet $peSubnet
204
+ $peSubnet = New-AzVirtualNetworkSubnetConfig - Name peSubnet - AddressPrefix " 11.0.1.0/24" - PrivateEndpointNetworkPolicies " Disabled"
205
+ $vnetPE = New-AzVirtualNetwork - Name $vnetName - ResourceGroupName $rgname - Location $location - AddressPrefix " 11.0.0.0/16" - Subnet $peSubnet
209
206
210
- $plsConnection = New-AzPrivateLinkServiceConnection - Name plsConnection - PrivateLinkServiceId $resourceId - GroupId ' Sql'
211
- $privateEndpoint = New-AzPrivateEndpoint - ResourceGroupName $rgname - Name $peName - Location $location - Subnet $vnetPE.subnets [0 ] - PrivateLinkServiceConnection $plsConnection - ByManualRequest
212
-
213
- $pecGet = Get-AzPrivateEndpointConnection - PrivateLinkResourceId $resourceId
214
- Assert-NotNull $pecGet ;
215
- Assert-AreEqual " Pending" $pecGet.PrivateLinkServiceConnectionState.Status
216
-
217
- # Approve Private Endpoint Connection
218
- $pecApprove = Approve-AzPrivateEndpointConnection - ResourceId $pecGet.Id
219
- Assert-NotNull $pecApprove ;
220
-
221
- $pecGet2 = Get-AzPrivateEndpointConnection - PrivateLinkResourceId $resourceId
222
- do
223
- {
224
- $pecGet2 = Get-AzPrivateEndpointConnection - PrivateLinkResourceId $resourceId
225
- } while ($pecGet2.PrivateLinkServiceConnectionState.Status -ne " Approved" )
226
-
227
- # Remove Private Endpoint Connection
228
- $pecRemove = Remove-AzPrivateEndpointConnection - ResourceId $pecGet.Id - PassThru - Force
229
- Assert-AreEqual true $pecRemove
230
-
231
- $pecGet3 = Get-AzPrivateEndpointConnection - PrivateLinkResourceId $resourceId
232
- do
233
- {
234
- $pecGet3 = Get-AzPrivateEndpointConnection - PrivateLinkResourceId $resourceId
235
- } while (($pecGet3 ) -ne $null )
207
+ $plsConnection = New-AzPrivateLinkServiceConnection - Name plsConnection - PrivateLinkServiceId $resourceId - GroupId ' Sql'
208
+ $privateEndpoint = New-AzPrivateEndpoint - ResourceGroupName $rgname - Name $peName - Location $location - Subnet $vnetPE.subnets [0 ] - PrivateLinkServiceConnection $plsConnection - ByManualRequest
209
+
210
+ $pecGet = Get-AzPrivateEndpointConnection - PrivateLinkResourceId $resourceId
211
+ Assert-NotNull $pecGet ;
212
+ Assert-AreEqual " Pending" $pecGet.PrivateLinkServiceConnectionState.Status
213
+
214
+ # Approve Private Endpoint Connection
215
+ $pecApprove = Approve-AzPrivateEndpointConnection - ResourceId $pecGet.Id
216
+ Assert-NotNull $pecApprove ;
217
+
218
+ $pecGet2 = Get-AzPrivateEndpointConnection - PrivateLinkResourceId $resourceId
219
+ do
220
+ {
221
+ $pecGet2 = Get-AzPrivateEndpointConnection - PrivateLinkResourceId $resourceId
222
+ } while ($pecGet2.PrivateLinkServiceConnectionState.Status -ne " Approved" )
223
+
224
+ # Remove Private Endpoint Connection
225
+ $pecRemove = Remove-AzPrivateEndpointConnection - ResourceId $pecGet.Id - PassThru - Force
226
+ Assert-AreEqual true $pecRemove
227
+
228
+ $pecGet3 = Get-AzPrivateEndpointConnection - PrivateLinkResourceId $resourceId
229
+ do
230
+ {
231
+ $pecGet3 = Get-AzPrivateEndpointConnection - PrivateLinkResourceId $resourceId
232
+ } while (($pecGet3 ) -ne $null )
233
+ }
234
+ finally {
235
+ Remove-AzPrivateEndpoint - ResourceGroupName $rgname - Name $peName - Force
236
+ Remove-AzVirtualNetwork - Name $vnetName - ResourceGroupName $rgname - Force
237
+ }
236
238
}
0 commit comments