1
votes

I have:

  • A V1 VNet (classic) named VNET_DEV01_CLASSIC2.
  • I have also a PowerShell Script that creates a WebApp (AppService) using ARM templates (Here you can see template).

The new WebApp is created ok but then I need to manually connect it to V1 VNet

enter image description here

After connecting it, it works perfectly.

enter image description here

How can automate this? So far I tried two approaches unsucessfully:

1) Updating ARM template to create it with the connection. I saw all the azure-quickstart-templates but did not found any WebApp that connect to VNet. I tried also to use Resource Explorer and deduct how would be the template resource, but unsuccessfully.

2) After creating it, add some PowerShell commands to connect it to V1 VNet I cannot find any article to do it. Here there is a comment from Ahmed IG that asks for the same and answered by compy@MSFT but the answer is not public...

I tried also to use Resource Explorer and follow PowerShell example but doesn't work. The error I am having is:

New-AzureRmResource : The pipeline has been stopped. At D:\cad\antstream\azure-devops\AzureManagementScripts\as-cms\kk.ps1:14 char:1 + New-AzureRmResource -ResourceName as-cms-dev01 -Location $ResourceLoc ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [New-AzureRmResource], PipelineStoppedException + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceCmdlet New-AzureRmResource : {"Message":"The requested resource does not support http method 'PUT'."} At D:\cad\antstream\azure-devops\AzureManagementScripts\as-cms\kk.ps1:14 char:1 + New-AzureRmResource -ResourceName as-cms-dev01 -Location $ResourceLoc ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [New-AzureRmResource], ErrorResponseMessageException + FullyQualifiedErrorId : MethodNotAllowed,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceCmdlet

enter image description here

So my question is How can automate this?

1

1 Answers

2
votes

First you need an existing VNet with P2S configured as per my post at http://www.techdiction.com/2016/01/12/creating-a-point-to-site-vpn-connection-on-an-azure-resource-manager-virtual-network/

Then use the below PowerShell to connect the AppService to the VNet using P2S VPN:

$subscription_id = "<Subscription_ID>"
$NetworkName = "<Network_Name>"
$location = "<Region>"
$netrgname = "<Resource_Group_VNet_is_in>"
$AppServiceName = "<AppService_Name>"
 $props = @{
      "vnetResourceId" = "/subscriptions/$subscription_id/resourcegroups/$netrgname/providers/Microsoft.ClassicNetwork/virtualNetworks/$NetworkName";
      "certThumbprint"= "<Client_cert_thumbprint>";
      "certBlob"= "<Base64_Cert_Data>";
      "routes" = $null;
      }

New-AzureRMResource -ResourceName "$AppServiceName/$AppServiceName-to-$NetworkName" -Location $location  -ResourceGroupName MarcusWebsites -ResourceType Microsoft.Web/sites/virtualNetworkConnections -PropertyObject $props -ApiVersion "2015-08-01" -force 

You can configure custom routes if you require by modifying the routes property.

Marcus