{"id":4941,"date":"2015-10-25T17:43:56","date_gmt":"2015-10-25T16:43:56","guid":{"rendered":"https:\/\/blog.redbaronofazure.com\/?p=4941"},"modified":"2015-10-29T12:37:06","modified_gmt":"2015-10-29T11:37:06","slug":"provision-webapp-to-a-appserviceenvironment-with-powershell","status":"publish","type":"post","link":"https:\/\/blog.redbaronofazure.com\/?p=4941","title":{"rendered":"Provision WebApp to a AppServiceEnvironment with Powershell"},"content":{"rendered":"<p>If you deploy your WebApps today to Azure using web deploy and the ServiceManagement API (ASM)\u00a0and you need to move WebApp to the AppServiceEnvironment (ASE) you are faced with the reality that the New-AzureWebsite powershell cmdlet do not support that. You need to add just a little bit of ResourceManager API (ARM) in the right place and you can continue to use the ServiceManagement APIs and avoid the big rewrite of your provisioning scripts.<\/p>\n<p><strong>How much needs to change?<\/strong><\/p>\n<p>The ServiceManagement cmdlets Get-AzureWebsite, New-AzureWebsite and Set-AzureWebsite work perfectly against a WebApp once it is created in the AppServiceEnvironment. So in theory, existing provisioning code that uses the web deploy technique can continue to work\u00a0once the WebApp is <a href=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/AddApp_Portal.png\"><img loading=\"lazy\" class=\"alignright size-full wp-image-4961\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/AddApp_Portal.png\" alt=\"AddApp_Portal\" width=\"466\" height=\"333\" srcset=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/AddApp_Portal.png 466w, https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/AddApp_Portal-300x214.png 300w\" sizes=\"(max-width: 466px) 100vw, 466px\" \/><\/a>created in the ASE. However, that model means that provisioning will be partly manual which becomes a burden if you have 20+ WebApps that should be deployed. So the only thing that needs to change is to find a new method to replace the call to powershell New-AzureWebsite, since that cmdlet only provisions the WebApp in the Free\/Shared\/Basic\/Standard Hosting Plan. We need to find a way to do what the &#8220;Add App&#8221; function do in the portal.<\/p>\n<p><strong>Resource Group Template<\/strong><\/p>\n<p>In order to solve this we need a Resource Group Template json file which we can create in Visual Studio via creating a new Cloud project of type &#8220;Azure Resource Group&#8221;.<\/p>\n<p><a href=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/VS_NewProject_ARG.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-4971\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/VS_NewProject_ARG.png\" alt=\"VS_NewProject_ARG\" width=\"786\" height=\"443\" srcset=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/VS_NewProject_ARG.png 786w, https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/VS_NewProject_ARG-300x169.png 300w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/a><\/p>\n<p>In that project you get a file named WebSite.json which you need to modify the following way:<\/p>\n<ol>\n<li>Add a &#8220;hostingEnvironment&#8221; parameter under parameters<\/li>\n<li>Add a &#8220;hostingEnvironment&#8221; under resources\/properties<\/li>\n<li>Remove everything in the json file after &#8220;type&#8221; : &#8220;Microsoft.Web\/sites&#8221; to keep the file minimalistic<\/li>\n<\/ol>\n<p><a href=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/Json_code_change_1_2.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-4981\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/Json_code_change_1_2.png\" alt=\"Json_code_change_1_2\" width=\"894\" height=\"266\" srcset=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/Json_code_change_1_2.png 894w, https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/Json_code_change_1_2-300x89.png 300w\" sizes=\"(max-width: 894px) 100vw, 894px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/Json_code_change_3.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-5001\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/Json_code_change_3.png\" alt=\"Json_code_change_3\" width=\"753\" height=\"402\" srcset=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/Json_code_change_3.png 753w, https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/Json_code_change_3-300x160.png 300w\" sizes=\"(max-width: 753px) 100vw, 753px\" \/><\/a><\/p>\n<p><strong>Provisioning script &#8211; putting it all together<\/strong><\/p>\n<p>We can now change\u00a0the script that provisions the WebApp to use the template and create the WebApp in the ASE if it doesn&#8217;t exist. It would look something like below. If the website do not exist we need to create it, but if it\u00a0should be deployed in an AppServiceEnvironment, then we switch to ResourceManager APIs, invoke the New-AzureResourceGroup passing the json template we created.<\/p>\n<p><a href=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/New-AzureResourceGroup_code.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-5011\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/New-AzureResourceGroup_code.png\" alt=\"New-AzureResourceGroup_code\" width=\"789\" height=\"379\" srcset=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/New-AzureResourceGroup_code.png 789w, https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/New-AzureResourceGroup_code-300x144.png 300w\" sizes=\"(max-width: 789px) 100vw, 789px\" \/><\/a><\/p>\n<p>There is one more thing you need to make sure you do and that is to use the correct url to deploy the web deployment package (zipfile). An AppServiceEnvironment do not use the xxxxxx.scm.azurewebsites.net url but the xxxxxx.scm.yyyyyy.p.azureweb, where xxxxxx is the name of the WebApp and yyyyyy is the ASE name. If you get the url from the property EnabledHostNames and look for the url that includes &#8220;.scm.&#8221; it will work, regardless if it&#8217;s an ASE hosted WebApp or not.<\/p>\n<p><a href=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/msdeploy_scm_url.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-5021\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/msdeploy_scm_url.png\" alt=\"msdeploy_scm_url\" width=\"1004\" height=\"206\" srcset=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/msdeploy_scm_url.png 1004w, https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2015\/10\/msdeploy_scm_url-300x62.png 300w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/a><\/p>\n<p><strong>Summary<\/strong><\/p>\n<p>By just creating the json resource template file\u00a0in Visual Studio, adding a few lines of code, and modifying the provisioning powershell script at one place, you can target AppServiceEnvironment as the hosting environment for your WebApps. Yes, you probably should start planning for the migration of your provisioning scripts to use ARM but using what I showed you here, you can leave that to the future for a while &#8211; Great Scott!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you deploy your WebApps today to Azure using web deploy and the ServiceManagement API (ASM)\u00a0and you need to move WebApp to the AppServiceEnvironment (ASE) you are faced with the reality that the New-AzureWebsite powershell cmdlet do not support that. You need to add just a little bit of ResourceManager API (ARM) in the right [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[231,101,141],"tags":[251],"_links":{"self":[{"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=\/wp\/v2\/posts\/4941"}],"collection":[{"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4941"}],"version-history":[{"count":0,"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=\/wp\/v2\/posts\/4941\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4941"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4941"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4941"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}