Copy existing Azure resource group items into another Subscription RG - azure

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.

Related

Best way to export Azure resource group configuration?

I've created a resource group on Azure containing all of my resources for my project that is coming to a close and I'd like to not be charged for the resources I will soon no longer be using. I'd like to come back to this project in the future however so my question is: is there a way of backing up my entire resource configuration so I can just redeploy it with ease in the future?
Many thanks.
Yes, You Can Export Resources from ResourceGroup which will generate a new template and that exported template you can download and you can import the template later when you need.
Select the resources from your resource group which you want to export and click on the export template.
Once the Template is generated you can find an Option of download template as shown below.
When you select custom deployment you can deploy the template which you downloaded.

Azure resource group Template download

I have a resource group with 20 resources(SQL, Web App ....)
I could not see the Resource group template while clicking the automation script button.
How can i download all the resource as a template?
It has, one failed deployment resource.
is there any way to get all resource template if i remove from there?
If you click on the Automation script all the resources ready to export as a template, except the resources which has errors.
Click on the deployment which has error message and delete.
For downloading, you have both options:
Click on Download option to store it into local machine.
Click on Add to library to save as a template.
Automate deploying resources with Azure Resource Manager templates in a single, coordinated operation. Define resources and configurable input parameters and deploy with script or code. Learn more about template deployment.
Lot of things have changed from 2017 to 2020, but I just want to add this, so that its helpful for others who are looking for help for downloading templates
Goto Resource Groups and select the resource
In the Settings section, click on Export Template
The templates zip file is downloaded into your windows downloads directory.
Thanks
Nate

How can I divide an existing template into linked Templates

Auto generated arm templates aren't meant to be production ready, they need refinement. that is expected.
How can a Devops staff divide auto generated ARM templates into Linked templates?
References
Linked Templates
https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-linked-templates
Azure ARM template deployment
https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-overview#template-deployment
How can a Devops staff divide auto generated ARM templates into Linked templates?
Per my understanding, you could leverage Azure Resource Group deployment project through visual studio for a simple to divide your ARM template into Linked templates manually.
After you created the deployment project, you could right click your deployment project and click "Add > New Item", choose "Azure Resource Manager Deployment Template", then copy/paste your existed ARM template into your azuredeploy.json, then you could enable JSON Outline window by clicking "View > Other Windows > JSON Outline", then you could choose the resources which would be divided into Linked template, then copy the related resource configurations (resource definition, variables, parameters,etc.) into a new "Azure Resource Manager Deployment Template". Here I divided the HostingPlan into a Linked template, when deploying my azure website, I would use the hosting plan linked template as follows:
Deploying azure website with a host plan linked template
Azure website deployment template: https://brucechen.blob.core.windows.net/arm-templates/websitewithlinkedtemplate.json
Then, check the latest deployment log under "SETTING > Deployments" section of your resource group as follows:

Deploy a resource group with App Service

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?

How can I download template json for an Azure Resource Group that I created in the portal?

I am trying to find a way to retrieve the JSON version of an Azure Resource Group that I created in the portal. I've looked through all the PowerShell documentation, tried scraping JSON from the portal, all to no avail. There are some earlier questions that state that it isn't supported, but they are all fairly old (in terms of Azure feature release speed).
Is there any way to get the JSON for a Resource Group created in the Portal UI? Or is the template approach the only way to go?
While it is possible to retrieve the JSON for a resource group from the Azure Resource Explorer, there are some caveats you need to be aware of.
Resource Explorer is a tool that describes the current runtime configuration rather than the deployment configuration that a resource template does. While it is primarily the same language there are a number of subtle differences.
For instance resource explorer will tell you the IP address that is assigned to a NIC, which isn't something that is possible to assign from a template.
While they can be a good starting point for building resource templates you will need to go through them and clean out the extraneous information.
Personally my three calling points in building resource templates are
Azure Resource Explorer
Azure Quickstart Templates
Azure Resource Manager Schemas
Between the three of those you can usually put together some concise, powerful templates.
There is a feedback item that is 'under review' to allow for the creation of full ARM templates from existing resource groups.
You can use the Azure Resource Explorer to view the JSON representation of your Azure resources. The source code is also available on GitHub in case if you want to learn how it works: https://github.com/projectkudu/ARMExplorer
This is now available in the Azure portal, portal.azure.com. If you browse to a resource group in the portal, under "All settings" for the resource group, there is now an "Export template" option.
Looking at portal.azure.com as of 3/28/2016 it looks like the options have changed from some of the previous responses...
Go to portal.azure.com and log in
Click on "Resource Groups"
Click on "All Settings"
Click on "Deployments"
Click on the particular resource/deployment for which you want to create a template
Click on "Export Template" near the top of the tile/page.
Note: Some of the deployments may not give access to the "Export Template" button. For these, you will most likely see a "Template Link" in the resource summary which gives access to the generic template for that resource deployment.

Resources