AZURE - Save VM ARM Template to Templates - azure

I am trying to save ARM Template of VM into the Templates in Azure but I am getting the following error:
The client 'admin#xxxx.onmicrosoft.com' with object id '1550f813-ee2g-492e-b353-8885c1f85746' does not have authorization to perform action 'Microsoft.Gallery/register/action' over scope '/providers/Microsoft.Gallery' or the scope is invalid. If access was recently granted, please refresh your credentials.

There are two possible solutions for the above :
You can use Template Specs feature instead of Templates feature.
You can ask your Azure Active Directory tenant admin to create the first
gallery template to turn on the ability to create templates for all users under
the same tenant.
Steps to Create Template Spec:
Go to Template Specs in portal.
Select Create template spec.
Fill in the form and create .
Note: Templates with the same name will be overridden by the latest version.
Reference:
Convert portal template to template spec - Azure Resource Manager | Microsoft Docs
Azure Templates - Failed to save template - Microsoft Q&A

Related

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.

Display error in UI of azure while entering parameter for ARM template

I want to display a dynamic error that shows up when a wrong name for storage account is entered(that does not follow Azure naming conventions) while deploying an ARM template. Right now i am taking input from user as parameter but no error message shows up. Is there a way to achieve this.
Azure has this feature as shown in the image below when we create a storage account but i dont know how to implement this using ARM template.
Azure error when wrong storageaccount name is entered
I am afraid that this feature is not available for now in ARM Templates.
Please look at these feedback:
ARM template parameter validation
Resource Group Template parameter validation

Azure portal Template Deployment not supporting Keyvault references

I have a set of resources and want to deploy them using Template Deployment feature in Azure portal. In my parameters file, I have few references to parameters in Key Vault as mentioned here. When deploying the template in Azure portal (clicking on Deploy a custom template) and supplying these values, the portal still asks for these parameters explicitly which I definitely cannot provide in plain text.
When using the same resources.json and parameters.json file in powershell, it works fine.Is the feature of KeyVault references currently not supported in Template Deployment done through portal ?
Yes, this is the case, but you can workaround that by wrapping you template with another template and that template will "get" the reference and pass it to the actual template.
reference: https://github.com/4c74356b41/bbbb-is-the-word/blob/master/_arm/parent.json#L151

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:

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