In this exercise, we will use the extension to create an ARM template from scratch. While doing so you experience the extensions capabilities such as ARM template snippets , validation , completions, and parameter file support.
What is JSON ARM and what is it useful for?
JSON, or JavaScript Object Notation, is a data interchange format that is commonly used for configuration and data exchange in modern applications.
In Azure Resource Manager, JSON templates are used to define and deploy resources in a declarative way.
This means that instead of writing imperative scripts to specify the steps required to create and configure resources, you can define the desired state of your resources using JSON templates.
Prerequisite:
- Visual Studio Code
- Azure Resource Manager Tools extension
- Azure CLI or Azure Powershell
- Azure subscription
Task 1: Create an ARM template
Step 1: Create and open with VSCode new file azuredeploy.json
- Enter
arm
into the code editor, which initiates Azure Resource Manager snippets for scaffolding out an ARM template.
Select arm!
to create a template scoped for an Azure resource group deployment
The result should be the template below:
Task 2: Add an Azure resource
Step 1: Scroll down to line 7 and place the cursor in the template resources block and then select arm-storage
You should see the following storage template below:
Task 3: Add template parameters
Parameters will be used to specify the storage account name.
Step 1: On line 4 place the cursor in the parameters block, type "
and select the new-parameter snippet.
This should add a parameter to your template.
Step 2: Set the name of the parameter to storageAccountName
and the description to Storage Account Name
.
Step 3: Add min and max storage account name
length
Step 4: Update name property to use it
- Navigate to line 14 on the resource storage
- Remove current name
-
Enter a double quote
"
and an opening square bracket[
, select parameters
Step 5: Enter round brackets and a single quote ' inside the brackets
A list of defined parameters will be listed, select the parameter
Task 4: Create a parameter file
A parameter file allows you to store environment-specific parameter values and pass these values in as a group during deployment.
Step 1: Right-click on the template (code editor) and select Select/Create Parameter File
Step 2: Select New
> All Parameters
Enter a name and choose a location for the parameter file
The extension between the parameter file and the template validates both the files together.
Task 5 Deploy the template
Step 1:
Open Visual studio code terminal or Azure Powershell
N.B: Make sure that on your Visual Studio Code you have singed in to your Microsoft account. To do this you need select the accounts icon and Turn On Cloud
Now...Deploy by pasting the following code on the CLI/Powershell:
az group create --name arm-vscode --location eastus
az deployment group create --resource-group arm-vscode --template-file azuredeploy.json --parameters azuredeploy.parameters.json
The first code was executed successfully now it will deploy and create an ARM resource group
Now we can head on to our Azure portal and check if indeed it has been created.
So far so good!
There you go you have successfully deployed.
If you prefer you can push your code to your Github repository as I have done:
Clean up Resources
Now that you have successfully deployed ensure you clean by deleting all the resources to avoid unnecessary incurred cost.
Log back to your Azure portal and search for resources that have just been created and ensure that you have deleted them.
Congratulations, on completing this tutorial.
Top comments (0)