如何使用PowerShell的ARM模板将Azure WebApp创建到现有v1 VNet?

时间:2016-02-03 13:48:17

标签: templates azure azure-powershell azure-resource-manager

我有:

  • 名为VNET_DEV01_CLASSIC2的V1 VNet(经典)。
  • 我还有一个PowerShell脚本,它使用ARM模板创建WebApp(AppService)(在这里您可以看到template)。

新的WebApp创建正常但我需要手动将其连接到V1 VNet

enter image description here

连接后,它完美无缺。

enter image description here

如何实现自动化? 到目前为止,我尝试了两种不合适的方法:

1)更新ARM模板以使用连接创建它。 我看到了所有azure-quickstart-templates但没有找到任何连接到VNet的WebApp。我还尝试使用Resource Explorer并扣除了如何成为模板资源,但未成功。

2)创建后,添加一些PowerShell命令将其连接到V1 VNet 我找不到任何文章来做。 Here有一个来自艾哈迈德IG的评论要求同样的问题并通过compy @ MSFT回答,但答案不公开......

我还尝试使用Resource Explorer并按照PowerShell示例进行操作但不起作用。我遇到的错误是:

  

New-AzureRmResource:管道已停止。在   d:\ CAD \ antstream \天青-DEVOPS \ AzureManagementScripts \作为-CMS \ kk.ps1:14   焦炭: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”:“请求的资源没有   支持http方法'PUT'。“}在   d:\ CAD \ antstream \天青-DEVOPS \ AzureManagementScripts \作为-CMS \ kk.ps1:14   焦炭: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

所以我的问题是如何实现自动化?

1 个答案:

答案 0 :(得分:2)

首先,您需要根据http://www.techdiction.com/2016/01/12/creating-a-point-to-site-vpn-connection-on-an-azure-resource-manager-virtual-network/

上的帖子配置已配置P2S的现有VNet

然后使用以下PowerShell使用P2S VPN将AppService连接到VNet:

$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 

如果需要,可以通过修改routes属性来配置自定义路由。

马库斯