DEV Community

Sarah-Nonye
Sarah-Nonye

Posted on • Edited on

How to create and deploy an Azure Resource Manager template

In this article, you will develop an Azure Resource Manager template (ARM template), deploy it to Azure, and then change the ARM template to add parameters and output.

I will explain the Azure Resource Manager Tools for Visual Studio Code as they will be used in this article. Before beginning the practice, make sure you have this extension installed in Visual Studio Code.

Creating an ARM template on Visual Studio Code.

Create a new file called azuredeploy.json in Visual Studio Code.

The Visual Studio Code ARM template addon includes snippets to assist you in creating templates. Let's begin with a blank template. Enter arm on the first line of the file.

VS Code prompts you for numerous options that begin with the letter "arm!" Select the Azure Resource Manager (ARM) template from the drop-down menu. (see image below)

The schemas and languages for your template are processed automatically by VS Code.

Image description

Your code file should have something like this:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"functions": [],
"variables": {},
"resources": [],
"outputs": {}
}

Remember to save with the ctrl + s command

Next stage is to:

Deploy the ARM template to Azure

First, Sign in to your Azure account from the Visual Studio Code shell to deploy this template to Azure. Make sure you're using the same account that you've installed Azure PowerShell Tools from the VS Code Extensions.

To open a PowerShell window, choose Terminal > New Terminal from the command bar.

If PowerShell appears in the terminal window's command bar, you're in the appropriate shell and may move on to the next phase.

Image description

If not, click the down arrow and choose PowerShell from the dropdown list. If that option isn't available, choose Select Default Profile.

Scroll down and pick PowerShell in the input area.

Select Terminal > New Terminal to open a PowerShell terminal window.

Image description

Azure PowerShell is used to log in to Azure.
To sign in to Azure, enter the following command from the console in Visual Studio Code. A browser window appears, allowing you to login in to your account.

Log in with the same account you used from the beginning. In the terminal window, VS Code lists the subscriptions linked with your account after you sign in. You'll notice a code block with the subscription name: This is the subscription that will be used throughout the rest of the exercise.

Set the default subscription for this session's PowerShell commands.
To get your subscription(s) and their ID, use the command below (s).

Get-AzSubscription

The second column is the subscriber ID. reveal the keys and copy the value

To change your active subscription to the your active Subscription, run the following command, substituting Your subscription ID with the one you copied in the previous step.

$context = Get-AzSubscription -SubscriptionId {Your subscription ID}
Set-AzContext $context

To make the default resource group the one generated for you in the sandbox environment, run the following command. This step allows you to leave that parameter out of the rest of the Azure PowerShell instructions in this article.

Set-AzDefault -ResourceGroupName [your resource group name]

More tips will be shared in the next article, I have no rights to the images used in my explanations.

Top comments (0)