Skip to content

Commit fe43c1d

Browse files
authored
Merge pull request #176398 from flang-steyer/fxl---Private-Endpoint-Document-for-Azure-Cache-for-Redis
Fxl---PowerShell and Azure CLI script added to Private Link
2 parents 60e7af2 + 2527f16 commit fe43c1d

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

articles/azure-cache-for-redis/cache-private-link.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,116 @@ To create a private endpoint, follow these steps.
203203
> There is a `publicNetworkAccess` flag which is `Disabled` by default.
204204
> You can set the value to `Disabled` or `Enabled`. When set to enabled, this flag allows both public and private endpoint access to the cache. When set to `Disabled`, it allows only private endpoint access. For more information on how to change the value, see the [FAQ](#how-can-i-change-my-private-endpoint-to-be-disabled-or-enabled-from-public-network-access).
205205
>
206+
## Create a private endpoint using Azure PowerShell
207+
208+
To create a private endpoint named *MyPrivateEndpoint* for an existing Azure Cache for Redis instance, run the following PowerShell script. Replace the variable values with the details for your environment:
209+
210+
```azurepowershell-interactive
211+
212+
$SubscriptionId = "<your Azure subscription ID>"
213+
# Resource group where the Azure Cache for Redis instance and virtual network resources are located
214+
$ResourceGroupName = "myResourceGroup"
215+
# Name of the Azure Cache for Redis instance
216+
$redisCacheName = "mycacheInstance"
217+
218+
# Name of the existing virtual network
219+
$VNetName = "myVnet"
220+
# Name of the target subnet in the virtual network
221+
$SubnetName = "mySubnet"
222+
# Name of the private endpoint to create
223+
$PrivateEndpointName = "MyPrivateEndpoint"
224+
# Location where the private endpoint can be created. The private endpoint should be created in the same location where your subnet or the virtual network exists
225+
$Location = "westcentralus"
226+
227+
$redisCacheResourceId = "/subscriptions/$($SubscriptionId)/resourceGroups/$($ResourceGroupName)/providers/Microsoft.Cache/Redis/$($redisCacheName)"
228+
229+
$privateEndpointConnection = New-AzPrivateLinkServiceConnection -Name "myConnectionPS" -PrivateLinkServiceId $redisCacheResourceId -GroupId "redisCache"
230+
231+
$virtualNetwork = Get-AzVirtualNetwork -ResourceGroupName $ResourceGroupName -Name $VNetName
232+
233+
$subnet = $virtualNetwork | Select -ExpandProperty subnets | Where-Object {$_.Name -eq $SubnetName}
234+
235+
$privateEndpoint = New-AzPrivateEndpoint -ResourceGroupName $ResourceGroupName -Name $PrivateEndpointName -Location "westcentralus" -Subnet $subnet -PrivateLinkServiceConnection $privateEndpointConnection
236+
```
237+
238+
## Retrieve a private endpoint using Azure PowerShell
239+
240+
To get the details of a private endpoint, use this PowerShell command:
241+
242+
```azurepowershell-interactive
243+
Get-AzPrivateEndpoint -Name $PrivateEndpointName -ResourceGroupName $ResourceGroupName
244+
```
245+
246+
## Remove a private endpoint using Azure PowerShell
247+
248+
To remove a private endpoint, use the following PowerShell command:
249+
250+
```azurepowershell-interactive
251+
Remove-AzPrivateEndpoint -Name $PrivateEndpointName -ResourceGroupName $ResourceGroupName
252+
```
253+
254+
## Create a private endpoint using Azure CLI
255+
256+
To create a private endpoint named *myPrivateEndpoint* for an existing Azure Cache for Redis instance, run the following Azure CLI script. Replace the variable values with the details for your environment:
257+
258+
```azurecli-interactive
259+
# Resource group where the Azure Cache for Redis and virtual network resources are located
260+
ResourceGroupName="myResourceGroup"
261+
262+
# Subscription ID where the Azure Cache for Redis and virtual network resources are located
263+
SubscriptionId="<your Azure subscription ID>"
264+
265+
# Name of the existing Azure Cache for Redis instance
266+
redisCacheName="mycacheInstance"
267+
268+
# Name of the virtual network to create
269+
VNetName="myVnet"
270+
271+
# Name of the subnet to create
272+
SubnetName="mySubnet"
273+
274+
# Name of the private endpoint to create
275+
PrivateEndpointName="myPrivateEndpoint"
276+
277+
# Name of the private endpoint connection to create
278+
PrivateConnectionName="myConnection"
279+
280+
az network vnet create \
281+
--name $VNetName \
282+
--resource-group $ResourceGroupName \
283+
--subnet-name $SubnetName
284+
285+
az network vnet subnet update \
286+
--name $SubnetName \
287+
--resource-group $ResourceGroupName \
288+
--vnet-name $VNetName \
289+
--disable-private-endpoint-network-policies true
290+
291+
az network private-endpoint create \
292+
--name $PrivateEndpointName \
293+
--resource-group $ResourceGroupName \
294+
--vnet-name $VNetName \
295+
--subnet $SubnetName \
296+
--private-connection-resource-id "/subscriptions/$SubscriptionId/resourceGroups/$ResourceGroupName/providers/Microsoft.Cache/Redis/$redisCacheName" \
297+
--group-ids "redisCache" \
298+
--connection-name $PrivateConnectionName
299+
```
300+
301+
## Retrieve a private endpoint using Azure CLI
302+
303+
To get the details of a private endpoint, use the following CLI command:
304+
305+
```azurecli-interactive
306+
az network private-endpoint show --name MyPrivateEndpoint --resource-group MyResourceGroup
307+
```
308+
309+
## Remove a private endpoint using Azure CLI
310+
311+
To remove a private endpoint, use the following CLI command:
312+
313+
```azurecli-interactive
314+
az network private-endpoint delete --name MyPrivateEndpoint --resource-group MyResourceGroup
315+
```
206316

207317
## FAQ
208318

0 commit comments

Comments
 (0)