Deploy a resource group with App Service - azure-api-apps

I have published an API app from Visual Studio to a new resource group, also created an App Service Plan, so after the deployment the resource group contains 2 items:
AppServicePlan1
AppService1
Now I am trying to deploy these items to another resource group as follows:
Select 'Automation script' in the resource group settings
Click 'Deploy'
Select 'Create new' resource group, enter its name
Enter 'Serverfarms_AppServicePlan1_name' parameter value (new app service plan name, e.g. AppServicePlan2)
Enter 'Sites_AppService1_name' parameter value (new app service name, e.g. AppService2)
Tick 'Agree to terms and conditions'
Click 'Puchase'
The process fails with the following error message:
"The host name AppService1.azurewebsites.net is already assigned to another Azure website: AppService1."
I have tried different things - deploying app service plan, logic apps, etc. from one resource group to another works fine, but deploying an app service fails as described above.
I have tried changing the hostNames property in the template file to ["AppService2.azurewebsites.net"] manually - I'm not getting the error then (although I'm not sure, maybe something else also needs to be changed, e.g. properties enabledHostNames, hostNameSslStates?) and the deployment seems to work, however the 'deployed' app service can't be used as it contains only 1 file - hostingstart.html.
What am I missing?

I think you have everything correct - as you noticed when you use the generated automation script it will create everything with the same properties that currently exist. We try to parameterize the correct value (like the web app name) but there are some details that can be overlooked (like host names). After changing all that it sounds like you got it to deploy.
The "code" however is not part of the automation script - only the infrastructure and configuration. So you still need to deploy your app to have it be identical. You can folder app deployment into the JSON template (using webdeploy or github) but since that requires access to external artifacts, that's not done automatically.
That help?

Related

Lookup Azure application name from within a running function app

Is it possible to lookup the application name for an Azure app as it runs, i.e., get the information about that is displayed in the Azure portal? In the example below, I'd want something to tell me from within the application that I am running sitemap-prod-eastus.
I've been looking at the Azure Context object but not seeing what I need. There is an invocation ID, a name for the function, a directory - not the info in this window.
Maybe this can be done through Azure Application Insights?
I am working in Node JS.
I've not seen anything that would expose this to a function app. That said, there is one sort of workaround that you could do which would work - go to the Configuration blade for the function app, Application settings tab, and add a configuration key like function_name and set its value to the name of your app. Your app could then just read it out of configuration.
It's an extra step, but if you're doing it with something like ARM or Terraform, it's just another configuration entry with a variable you already declared to set up the app in the first place.
Answering my own question: Azure provides WEBSITE_SITE_NAME in the runtime environment that matches the name of the function app.

How to change Azure App Services Github workflow deployment environment name

When you create an app there's no option to customize this, it's just there by default.
This matters because sometimes I don't want github actions to say that I'm deploying to "production", I want it to say I'm deploying to "development". But if I change this property manually, I'll get an error in github actions saying: Error: Deployment Failed with Error: Error: Publish profile is invalid for app-name and slot-name provided. Provide correct publish profile credentials for app. But then as soon as it's changed back the deployment works again, so I need to find a way to change this property in Azure?
Always the main slot of the webapp is called production, there is no way to change it.

Copy existing Azure resource group items into another Subscription RG

All I want is to copy/recreate all the existing resources which is under resource-grp1 from a Production environment to another resource-grp2.
What would be the very easiest way to re-create the same environment in another Resource Group in the same subscription? I tried to export the resource group and downloaded. The problem is that the file “parameters.json” includes hard coded references to the original resource group name. Is there an way to do this without using Azure CLI/Powershell, only use Azure Portal
resource-grp1 contains following resources
1. 2 app service plans
2. 10 app services
3. 8 azure sql database
4. 3 NSG & vnet
5. Application Insight
6. SendGrid
6. Storage account
7. VM
You can just navigate to your Resource group > Click on Export Template from side Panel
You'll have 3 options
Download
Add to Library
Deploy
When Downloaded, the ARM Template will be saved to the local machine. This will allow for the template to be manually changed or saved somewhere for it to be retrieved for later use.
When Saving, the ARM Template will be saved to a collection accessible from “Browse > Templates” within the Azure Portal. This allows for Resource Group configurations to be saved so they can easily be redeployed later.
When Deploying, the ARM Template will be deployed to a new Resource Group. This essentially allows for the Resource Group to be “copied.” This could be useful for easily cloning a Resource Group to easily spin up a separate hosting environment with identical settings.
enter image description here
I have Downloaded the template and Imported the template using Template Deployments.
Search for Template Deployments > Build your own template in editor > Load File (Add your downloaded template after unzipping) > Save > Create
enter image description here
enter image description here
enter image description here
you can refer this site for more
If you are facing issue with Export template "The problem is that the file “parameters.json” includes hard coded references to the original resource group name" try below.
Azure portal - > Resource group -> Export Template and download the template.
After download the templates (template.json and parameters.json) files find old resource group reference and change into new resource group reference.
Deploy into other resource group:
Search Template Deployment in Azure portal search bar and click on create.
Click on Build your own template in the editor
select parameter and add updated parameters.json file
&
select resources and add updated template.file and save it.
Add subscription and Resource group which you need to deploy.
Click Create it will deploy your resources in a new resource group.

Error while creating bot

I am getting error while creating bot. I am trying to deploy a Web app bot. After specifying the name of resource group and their location I click on create. After which bot deployment process starts. But it ends up with an error:
MsaAppId: MsaAppId is already in use..
What can I do successfully deploy a basic bot. This is second time in a week, I am facing something like this on Azure.
Edit
Initially I was using Autocreate MsaAppId & Password option. That didn't work out (although that used to work)
Then I tried a couple of times with Create MsaAppId & Password option. Which takes to a different page to generate AppId & password, and I pasted the new keys in the provided fields.
Still the same result. MSA App Id already in use
Edit 2
As one of the answer mentioned, I tried creating a separate Bot Registration which I will link up with the Web app later.
But that fails with a weird message saying, App Insights is already deployed, and cannot deploy with same name, when in fact, I have not asked for any new App Insights instance to be deployed. Attaching a screenshot
it ends up with an error:
MsaAppId: MsaAppId is already in use..
I have same problem, when I create the web app bot (select Auto create App ID and password option), it failed at creating botServices resource.
Deployment:
Failed operation details:
I also tried to manually create app on https://apps.dev.microsoft.com and provide App ID and password for creating botService, but the deployment still failed.
As a workaround, I manually created Bot Channels Registration and specify corresponding web application URL as message endpoint, and then modify Application settings of that corresponding Azure web site with new App ID and password, which works for me.
Note:
I suspect something wrong with Azure while performing deployment and creating botServices, if possible, you can report it on Azure portal or create an issue on github.
Updated:
I click Automation options and download the template after I enter the required information/fields for creating a new web app bot, and then I perform deployment by using powershell with downloaded template&parameter file, which work for me, you can try it.

Azure ARM template nested template deployment won't update resources\fails to start

I have the following ARM Template structure:
Parent Template
|--Nested Template 1
|--...
|--Nested Template 6
So I only have 2 levels of templates, Parent and nested.
Lets say I deploy parent to an empty resource group and everything works well. After that I delete one of the resources and want to deploy the same Parent Template with the same parameters to bring deleted resources back. But the deployment would fail saying that the resource already exists (the other, not the one i'm tried to recreate). I tried both incremental mode and full mode for deployments.
If i directly invoke nested template with the missing resources it works as expected (so specifically creating a deployment with nested template only, not with parent that invokes nested template).
UPD:
After some additional testing I can conclude thats even weirder then before. So I'm starting this deployment with powershell:
New-AzureRmResourceGroupDeployment #parameters
And it deploys just fine, however if I invoke the same command after the first deployment completed I would get an error:
The resource 'gggg-1s-the-wordd' already exists in location
'westeurope' in resource group 'gggg'. A resource with the same name
cannot be created in location 'northeurope'. Please select a new
resource name.
Is this behavior excepted? I can't seem to find anything relevant, thanks!
UPD2: It doesn't really matter if I use portal or powershell, I get the same error.
So with the help from Brian we were able to identify the culprit. The issue was that the WebApp had its location set to resourcegroup().location while the App Service Plan was correctly getting location from parameters. So that lead to a problem where at deployment time WebApp would deploy to the region where its App Service Plan was, but at evaluation time it would consider that this WebApp belongs to the region where the resource group was.
TLDR - copy paste error, which coupled with a bug in evaluation of location in ARM lead to a quite weird behavior.
If you deploy the same resource (intentionally did not use the word "template" there) to the same resource group, Azure should "make it so". IOW, if it's not there, it will create it, if it is there, it should no-op. It's not that black and white there are some nuances (like you can't change certain properties if the resource exsists) but if you deploy the same resource with the same property values to the same resource group you should not get an error.
In general, nesting (or not) shouldn't affect any of this.
If you're deploying to different resource groups, then you could see an error about "already exists" depending on the resource.
All that said, it's really hard to tell in your specific case what's going on without more detail... So if this doesn't help, can you add some detail (what's the exact error message) or a repro (template that we could see the problem with)?
I experienced the same issue. The reason was that, location of App Service was defined as [resourceGroup().location] instead of App service plan (ASP) location, which was creating the problem. I changed it by passing the location of ASP as a parameter to the template.
Getting location of of ASP is as:
internal static string GetASPLocation(TokenCloudCredentials credentials, string resourceGroup, string ASP)
{
Console.WriteLine($"Getting location of App Service Plan {ASP} in Resource Group {resourceGroup}");
var resourceClient = new ResourceManagementClient(credentials);
ResourceExistsResult result = resourceClient.Resources.CheckExistence(resourceGroup, new ResourceIdentity(ASP, "Microsoft.Web/serverfarms", "2015-08-01"));
var appServicePlan = resourceClient.Resources.Get(resourceGroup, new ResourceIdentity(ASP, "Microsoft.Web/serverfarms", "2015-08-01"));
return appServicePlan.Resource.Location;
}
And in ARM template, location can be changed as :
"location": "[parameters('ASPLocation')]"

Resources