In this blog post, I will show you how to deploy resources to Azure Resource Manager (ARM) and get into the learning of Infrastructure as a code.
In my previous blog post, I explained why you should start using ARM, but in a nutshell, ARM gives the ability to be more consistent with our deployment and have a record of them in a readable format that allows us to review at any point in the future without the need to reverse engineer what was done.
VS Code extensions
To get started with the right tools. You will need the following two VS Code extensions the are listed below.
- ARM Tools
- Azure Account
Create a JSON file
After installing the extensions, I will create a .JSON file called sample.json which I will use for my first deployment.
After creating the file, I will open it and start typing ARM as shown belo and will select the the first option (arm!).
This will bring up an ARM template.
Below you can see the ARM template that was loaded by the ARM extension.
Create a MySQL Database
Let’s go ahead and create a MySQL database in Azure. In the resource, section starts typing my, and you will see the arm-MySQL option. You can start writing any service you would like to deploy, and you will see its template.
After selecting the MySQL option, The template will load the MySQL configuration. I will go ahead and rename the name and set the admin username and password.
Deploy Template using Azure Cloud Shell
To make this process a bit easier, I will use Cloud Shell to deploy the template. I will log in to Cloud Shell and use the PowerShell console, as shown below.
After login in I will run the following cmdlet which will create a new resource group for the deployment named ARMDemo1.
New-AzResourceGroup -Name ARMDemo1 -Location southeastasia
Next, I will upload the template file to Cloud Shell using the upload button on the top Shell screen of creating a new file and copy-paste the template.
Below, is the deplyment cmdlet which will deploy the MySQL database to Azure.
New-AzResourceGroupDeployment -Name Deploy001 -TemplateFile ./sample.json -ResourceGroupName ARMdemo1 -Verbose
After a minute or two the MySQL database will show up in the Azure resource group.
To remove the deployment you can use the following cmdlet.
Remove-AzResourceGroupDeployment -ResourceGroupName ARMDemo1 -Name Deploy001