Skip to content

Examples and documentation on how to write good ARM templates

License

Notifications You must be signed in to change notification settings

nilshedstrom/ARMTemplatesDeepDive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ARMTemplatesDeepDive

Examples and documentation on how to write good ARM templates. You can find the video of my presentation at Swetugg 2020 on Youtube

Introduction

Azure Resource Manager Templates (ARM Templates) are a way to define a set of resources in Azure. When you deploy the ARM template the Azure Resource Manager will create the resources in your ARM template. If you are new to ARM templates and want to learn more the tutorials at Azure Resource Manager template documentation is a really good place to start.

Chapters

This repo is a source for all the examples used in the presentation Deep dive into writing good ARM templates and each topic is covered in one chapter (directory in GitHub).

Explains the basic structure of ARM templates with an example of a Storage Account

Explains how you can use parameters to have different resource names and configuration when you deploy the same ARM template to different environments/resource groups.

Explains how you can reduce code duplication and increase readability and maintainability of your ARM templates by introducing variables with good names.

Explains how you can configure one resource with the run time value of another resource by using the reference function. This can be useful when you want to configure an App Service to use an Application Insights instance that you create in the same ARM template.

Explains how you can sometimes skip the creation of a resource by using the condition feature and change the value by using the if-function. This can be useful if you want several App Services to use the same App Service Plan.

Explains how to use the copy feature to create multiple resources with similar configuration in the same resource group. This can be useful when you want to create multiple App Services in different locations in the same resource group.

Explains how to use Deployment Scripts to run custom Powershell scripts when you deploy your ARM templates. This can be useful when you want to create resources that are not possible with normal ARM Templates, such as:

  • Storage Tables
  • Azure Active Directory Applications
  • Chatbots
  • Certificates in KeyVault

Other topics

There are some topics that I feel is important but did not have the time to cover in my presentation

User-defined functions

The concept of user-defined functions is the same as in most programming languages and you can reduce them to reduce code duplication and increase readability and maintainability. Check this article to learn how to create your own user-defined functions. Pay attention to the limitations because you cannot use them in all scenarios.

Unit tests

As with normal code you might want to run Unit tests on your ARM templates. There are two types of Unit tests:

Linked templates

If your ARM templates gets too big or you need to modularize your templates you might consider splitting your template into several smaller ones and have one call the other ones. The process is described in Tutorial: Create linked Azure Resource Manager templates and Using linked and nested templates when deploying Azure resources. Keep in mind that your deployments will get more complicated.

Sources of documentation for ARM templates

Recommended plugins for Visual Studio Code

  • Azure Resource Manager (ARM) Tools A must have when you are working with ARM Templates in Visual Studio code. Gives you code completion, validation, colorization and much more.
  • ARM Template Viewer Gives you a graphical preview of your ARM template.
  • ARM Params Generator Gives you the ability to extract selected value to parameters or variables and the ability to create a parameters file from for the current ARM template. This functionallity might be included (and improved) in the ARM Resource Manager Tools in a near future.
  • Highlight In the different templates in this repository I have added comments with <NewStuff> where the new stuff (since the last chapter) begins and </NewStuff> where the new stuff ends. If you want to make the new stuff bold and almost remove the <NewStuff> tags you should install this plugin with the following settings in settings.json
"highlight.regexes": {
    "(/\\* <NewStuff> \\*/)(.*?)(/\\* </NewStuff> \\*/)": {
        "regexFlags": "gms",
        "filterLanguageRegex": "arm-template|json|jsonc",
        "decorations": [
            { "opacity": "0.05" },
            {
                "overviewRulerColor": "#00ff00",
                "fontWeight": "bolder"
            },
            { "opacity": "0.05" },
        ]
        }
},
"highlight.maxMatches": 500,

About

Examples and documentation on how to write good ARM templates

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published