Is it possible to move an already setup app gateway from one subnet to another?
As of now haven't seen any way from the portal to do so.
Is it possible to move an already setup app gateway from one subnet to another?
As of now haven't seen any way from the portal to do so.
You can use this script to change the VNet or Subnet. Please test it to see if it meets your needs, before applying it to a production gateway. Also, take into account that there will be some downtime during the change.
#Login to Azure RM
Login-AzureRmAccount
#Get the Application Gateway config
$gw=Get-AzureRmApplicationGateway -Name GatewayName -ResourceGroupName RGName
#Set the new virtual network and store the config into a new variable
$gw2=Set-AzureRmApplicationGatewayIPConfiguration -SubnetId "/subscriptions/999999-9915-4b1c-accf-0c984bed2311/resourceGroups/RGName/providers/Microsoft.Network/virtualNetworks/NewVirtualNetwork/subnets/default" -ApplicationGateway $gw -Name $gw.GatewayIPConfigurations.name
#Stop the Gateway (you can't change the virtual network / subnet if the Gateway is running)
Stop-AzureRmApplicationGateway -ApplicationGateway $gw
#Set the new config
Set-AzureRmApplicationGateway -ApplicationGateway $gw2
$subnet = Get-AzureRmVirtualNetworkSubnetConfig
, then use -Subnet
-argument. That's more PowerShellish / object-based approach. –
Symptomatology The accepted answer by andresm53 is excellent.
However, as the PowerShell AzureRm module is being phased out in favor of the newer Az module, here is an Az version (with a slight improvement to save from having to look up the subnet id in order to paste it into the code).
This is based, in addition to andresm53's code, also on an example in the MS docs.
### Fill in your values ###
$GatewayResourceGroupName = "MyRG1"
$GatewayName = "MyGw"
$VnetResourceGroupName = "MyRG2" #may or may not be the same as $GatewayResourceGroupName
$VNetName = "MyVNet"
$SubnetName = "Subnet1"
###########################
$AppGw = Get-AzApplicationGateway -Name $GatewayName -ResourceGroupName $GatewayResourceGroupName
Stop-AzApplicationGateway -ApplicationGateway $AppGw
$VNet = Get-AzVirtualNetwork -Name $VNetName -ResourceGroupName $VnetResourceGroupName
$Subnet = Get-AzVirtualNetworkSubnetConfig -Name $SubnetName -VirtualNetwork $VNet
$AppGw = Set-AzApplicationGatewayIPConfiguration -ApplicationGateway $AppGw -Name $AppGw.GatewayIPConfigurations[0].Name -Subnet $Subnet
Set-AzApplicationGateway -ApplicationGateway $AppGw
Start-AzApplicationGateway -ApplicationGateway $AppGw
I did it using azure cli, it's necessary to perform some steps:
Using azure cli:
az network application-gateway stop --subscription YOUR_SUBSCRIPTION_NAME --resource-group YOUR_APP_GATEWAY_RESOURCE_GROUP --name YOUR_APP_GATEWAY_NAME
az network application-gateway show \
--subscription YOUR_SUBSCRIPTION_NAME \
--resource-group YOUR_APP_GATEWAY_RESOURCE_GROUP \
--name YOUR_APP_GATEWAY_NAME
The output we need is at JSON section gatewayIpConfigurations
[
{
"etag": "REDACTED",
"id": "REDACTED",
"name": "REDACTED",
"provisioningState": "REDACTED",
"resourceGroup": "REDACTED",
"subnet": {
"id": "/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Network/virtualNetworks/YOUR_CURRENT_VNET/subnets/YOUR_CURRENT_SUBNET",
"resourceGroup": "REDACTED"
},
"type": "Microsoft.Network/applicationGateways/gatewayIPConfigurations"
}
]
[
{
"etag": "REDACTED",
"id": "REDACTED",
"name": "REDACTED",
"provisioningState": "REDACTED",
"resourceGroup": "REDACTED",
"subnet": {
"id": "/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Network/virtualNetworks/YOUR_CURRENT_VNET/subnets/YOUR_NEW_SUBNET",
"resourceGroup": "REDACTED"
},
"type": "Microsoft.Network/applicationGateways/gatewayIPConfigurations"
}
]
az network application-gateway update \
--subscription YOUR_SUBSCRIPTION_NAME \
--resource-group YOUR_APP_GATEWAY_RESOURCE_GROUP \
--name YOUR_APP_GATEWAY_NAME \
--set gatewayIpConfigurations[0].subnet.id='/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Network/virtualNetworks/YOUR_CURRENT_VNET/subnets/YOUR_NEW_SUBNET'
az network application-gateway start \
--subscription YOUR_SUBSCRIPTION_NAME \
--resource-group YOUR_APP_GATEWAY_RESOURCE_GROUP \
--name YOUR_APP_GATEWAY_NAME
You cannot change Subnet/VNet association on a running Gateway. It needs to be in stopped state first. Also the VIP on the Gateway would change once it is started post update. Subnet move can be done via PowerShell/CLI and is not supported in portal currently.
It will affects the external IP address. Therefore the app gateway have to use dynamic ip address.
Once the app gateway has been stopped than the external IP will release so you will have a new one after it's started up.
© 2022 - 2024 — McMap. All rights reserved.