Making Your Existing ARM Templates Reusable Using Parameters and Functions

45 minutes
  • 3 Learning Objectives

About this Hands-on Lab

In this lab, we will practice making an existing ARM template more reusable so that it can be deployed to multiple environments. We will do this by replacing some of the hardcoded elements with functions and adding parameters, along with a parameters file.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Add Parameters
  • Grab the initialdeploy.json file to be edited from this provided GitHub repository.
  • Add parameters in the ARM template deployment file for the following:
    • VM Username
    • VM Password
    • VM Environment (dev or prod)
Add Functions
  • Add a function so the VM will be deployed to the resource group location automatically.
  • Add a function to create a unique name for the VM based on the resource group ID.
  • Create a function to determine if the environment is dev or prod, and to change the size of the VM accordingly:
    • Dev: Standard_DS1_v2
    • Prod: Standard_D2s_v3
Add the Parameters File and Deploy
  • Create a parameters file for the parameter values.
  • Deploy the template with the parameters file.

Additional Resources

You should be familiar with the following to use this hands-on lab:

  • ARM Templates
  • Azure Virtual Machines
  • Azure Cloud Shell
  • Azure PowerShell/Azure CLI

Note about Lab Startup:

When starting up the lab environment, you may see an error, such as:

An error occured when trying to fetch resources. Additional details from the underlying API that might be helpful: Please provide below info when asking for support: timestamp = 2022-02-08T18:43:45.8593786Z, correlationId = 11343c5a-9f20-4ef0-a67d-614bbe889e37. (Code: AccessDenied) Access is denied to the requested resource. The user might not have enough permission. (Code: AccessDenied) Try refreshing the page. Your resources aren't affected by the issue, we're just having trouble showing this view right now. To see a list of resources, select Simplified View.

This is a known error and can be disregarded. It will not prevent you from working in the lab environment.

Lab Files

 https://github.com/linuxacademy/content-intro-to-azure-resource-manager/tree/main/lab-making-your-existing-arm-templates-reusable-using-parameters-and-functions

Note about Environment Limitations

Due to some limitations for the Cloud Playground/Hands-On Lab environments, there are some actions that are not permitted. One of these limitations is that only certain resource sizes/SKUs are permitted to be deployed.

How does this apply to our scenario?

We will add a function to an ARM template in the lab to deploy a VM with a certain size based on whether it is being deployed to dev or prod. Due to the Cloud Playground/Hands-On Lab environments, only the sizes listed in the article below can be used.

I understand that this is a bit confusing due to the unique limitations of the ACG environments, so please feel free to reach out if you are experiencing problems or if you have any other questions.

Click to learn more about the A Cloud Guru environment limitations.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?