Best practice for Azure ARM template parameters - azure

Getting started with ARM templates and trying to get a better understanding of what parameters go in a separate parameters file versus in the parameters section of the template itself. Do I have to have a separate parameters file? Seems like I can 't do a deployment from Visual Studio without identifying the parameters file.

You don't have to have a parameters file to deploy via ARM templates. You can certainly hardcode everything in your ARM template file if you like.
The next part is my opinion only on ARM template construction. I like following naming conventions for resources, such as [resource type]-[app]-[environment]. For example, a Web App for app Foo for the staging environment might be named wa-foo-prod. Following such a convention means that I can look at a resource and pretty much tell exactly what it's for.
That being said, I'm a big proponent of variables for naming resources in ARM templates. I might only pass in the environment and the region as parameters in an ARM template, then use variables to concatenate up all of the necessary resource names.
If every single resource name is passed in as a parameter, parameter management gets unwieldy.
As far as a required parameters file for deploying through VSTS, you may be right. But if you did NOT want any parameters, you could either deploy your ARM template through a Powershell script in VSTS, or just pass in an empty parameters file.

Related

Azure resource manager template deployments - Using _artifactsLocation and _artifactsLocationSasToken

Where and how to use artifactsLocation and _artifactsLocationSasToken in Arm template deployments. Are these used only for nested deployments.
Can we use these for custom VM extension of the Virtual machine as part of post provisioning activity, after VM is built or should the extension be added as part of the VM build deployment template only.
VM Custom script extension - (Initialize and format data drives, Mount file shares for instance)
Azure quick start templates, have the parameter values for these as default for artifactsLocation and type securestring for _artifactsLocationSasToken. How these values are populated in the ARM deployment runtime.
It would be great if someone can provide documentation around the same / step by step process or share an existing working custom script extension template.
There's nothing inherent in the platform that makes _artifactsLocation and _artifactsLocationSasToken special... it's just a pattern (well used) that has developed for staging artifacts needed for a deployment. The pattern is to stage all artifacts together and then use the uri of the main template as a relative location. The defaultValue generally used for _artifactsLocation is:
"defaultValue": "[deployment().properties.templateLink.uri]"
The deployment() function is inherent and contains the uri passed in for the main template.
That said, you can use those values anyway you see fit and the primary use case is for retrieving any artifact needed by any resource. For example:
Custom Script Extension
https://github.com/Azure/azure-quickstart-templates/blob/master/demos/vm-winrm-windows/azuredeploy.json#L256-L259
MSDeploy Packages for WebApps
https://github.com/Azure/azure-quickstart-templates/blob/master/demos/private-endpoint-sql-from-appservice/azuredeploy.json#L277
DSC Configuration Modules
https://github.com/Azure/azure-quickstart-templates/blob/master/demos/iis-2vm-sql-1vm/azuredeploy.json#L585
etc, etc...
That help?

How do i export an ARM template correctly from Azure?

I have already installed my azure environment with a VM, a storage account and a data base server, and it works fine, but now i want to export the ARM template in order to automate the whole proccess to my customers. The problem is that when exporting this message shows up:
error
So the question is how do i export an ARM template correctly from Azure with all my resources without having to do much fixing my final template?
that is expected. some resource types cannot be exported. you'd have to take a look at the api definition and use that to export those (say at resources.azure.com)
Simple: use bicep. Azure Resource Manager's transpiler (it's a sweeter syntax that solves your needs)
In Bicep the directive you're looking for in your Azure Resource Manager "ARM" template is keyword "existing"
https://github.com/Azure/bicep/blob/main/docs/tutorial/05-loops-conditions-existing.md
keyword "existing" lets you reference a resource without a complete definition.
Otherwise you need to provide the entire ARM definition for the object.
Export failures per resource type occur when a given resource types schema is not available. We are looking into how we can autogenerate schemas for Azure resource providers and onboarding them to this new process, improving the overall success of the Export Template API.

Azure ARM Deployment - multiple subscriptions

My ARM template has worked well, it creates a VNET, multiple subnets, NSGs, and necessary route-tables. I now need to do this same thing but across multiple subscriptions. Can't get it to work.
I know there is the nestedTemplate option. This allows you to specify a subscriptionID and requires that the resource group exist first. I built all this up and used the nestedTemplate but get an error "Subscription is not registered with NRP". Not sure how to make this work and I'm wondering if an ARM template is enough. I'm thinking of building a python script that will in turn run arm templates with separate parameter files.
I'd like to be able to take this single template and single parameter file but have it iterate through multiple subscriptions.
Couldn't get it to work, the nestedTemplates seem to require additional work. I built a python script that does the work instead.

Working with azure templates incrementaly

So I have this template that I've used to create my resource group. We are in the middle of development process, so it is pretty usual to add different resources from day to day.
How can I run the template to just add the ones that I am missing?
I've tried to deploy my template to my existing resource group, but I guess it just thinks that I want to create another set of resources.
What should I do?
ARM Templates are idempotent by default, so if you add resources to the template without changing anything else in it, it will just create\add new resources to your resource group. So that behavior is be default.
As for the parameters, it cannot magically infer the names (or anything) of things that you want to pass. You can either reuse existing deployments (it will prepopulate all the parameters), create a script that will pass in parameters, create a parameters file to pass in to the template.
Reference:
https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-deploy

Azure Resource Manager Template parameters

I am trying my hands on over Azure Resource manager templates.
So for making any new resource I am trying to find out which all parameters are required and if they are mandatory or optional. But couldn't get any documentation for same.
I am looking for documentation which is somewhat similar to AWS. To get better in sites about the resources.
Thanks in advance!!
EDIT
I am not looking for parameters in general which are passed to the template. What I want is the resources parameters. The parameters which are given under the properties tag of every resource
Example-
In the below resource "virtualNetworks" there are resource parameters like addressSpace, subnets.
virtualNetworks
This should help you.
It is the schema for deployment templates. Within it, there are schemas for every type of resource that can be put into an arm template. For example, if we look at the schema for Virtual Machines, it contains all the available properties, profiles, extensions, what is required or not, etc.
However, it shouldn't be necessary for you to really look at this and learn it. When you are creating your arm template in visual studio, intellisense should kick in and show you whether what you are putting in the template is valid or not. For example, here I am editing the properties of a public IP, and it shows me what the available properties to add are.
you are right, there is a lack of documentation for resources and required parameters.
My advice is:
Check the Azure-Quickstart Templates, more than enough examples: Quickstart Templates
Since some days you can export ARM Templates from the Azure Portal. So create your resource in portal and export the Templates & Parameters: Microsoft Blog
Check the resource Explorer: Resource Explorer

Resources