In this short, focused article, I’ll show you how to create a resource group through PowerShell, an ARM template or via the Azure Portal.
PowerShell
Either in Cloud Shell or locally using PowerShell and the Azure PowerShell module, run the New-AzResourceGroup cmdlet. Take a look at this post to see how to install the Az PowerShell module if it is not currently installed on your local machine.
NB: if you are not using the Cloud Shell then login into your Azure account using Connect-AzAccount
– see the MS documentation for more info.
You can also use Add-AzAccount
or Login-AzAccount
as these are aliases for Connect-AzAccount
.
PS Azure:> New-AzResourceGroup -Name vnetTestResourceGroup -Location WestEurope
When specifying the region, choose one from the following list:
- eastus, eastus2, westus, westus2, centralus, northcentralus, southcentralus, westcentralus
- eastasia, southeastasia
- northeurope, westeurope
- japaneast, japanwest
- brazilsouth
- australiasoutheast, australiaeast, australiacentral
- westindia, southindia, centralindia
- canadacentral, canadaeast
- uksouth, ukwest
- koreacentral, koreasouth
- francecentral
- southafricanorth
- uaenorth
ARM Template
The following json can be used to create a new resource group, it’s a most basic format as you’d likely want to parametise the resource group name, tags and location.
{ "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": {}, "resources": [ { "name": "armTemplateTest", "type": "Microsoft.Resources/resourceGroups", "apiVersion": "2018-05-01", "location": "uksouth", "tags": {}, "properties": { } } ] }
Once you have created a new template you will have a few options as to how you can deploy this. Unfortunately at this point in time you cannot deploy subscription-level resources direct from the Azure Portal templates blade. This means that if you try to deploy the resource group you will be asked which resource group to deploy it into!
Deployment options are:
- PowerShell
- Azure CLI
- Azure API calls
I’ll hopefully come back to provide examples for each of those methods but for now I will use the Azure CLI.
Import the template file to your clouddrive (in brief; open the storage blade, select the storage account (cloud-shell-storage-<location>) and then open the storage explorer and select file shares.)
With the console open in PowerShell mode, navigate to your clouddrive folder – I have created a sub folder called “templates”:
cd $home/clouddrive/templates
Listing the directory should show the template that you just created and imported.
Now to deploy the template we use az deployment create specifying the location where we would like to create the resource group and the template we wish to deploy from.
az deployment create --location uksouth --template-file resourceGroup.json
In the json returned after the deployment you should see “outputResources” confirming the name of the new resource group. Further down there will be a “provisioningState” which should say “successful”.
Azure Portal
The final method that I’d like to show you is via the Azure portal, this is possibly the first way that you will try using as it is easy and quick. Moving forward though you’ll likely want to use either PowerShell or ARM templates so that you can include the task into a pipeline.
From the portal home screen, search for and select “resource groups” and then click “Add”.
Next, select your subscription, resource group name and location.
Click “Review + Create” unless you want to add some tags to the group, we’ll skip that as this is a brief demo. Finally, click “Create”.
Azure Portal will go ahead and create the resource group pretty quickly.
Summary
In this article we have seen three different ways to create a new resource group:
- Azure Portal
- Easy to use GUI
- Quick to deploy
- PowerShell
- Slightly more long-winded than Portal
- Can be included in a pipeline
- Azure CLI
- Like PowerShell, not as quick as the Portal
- Can be included in a pipeline
- Template describes the infrastructure – Infrastructure as Code (IaC)
- Templates can be kept in a Source Control System (SCC)
For me personally, I have been used to using the Portal for most of my resource generation but I am transitioning across to ARM templates as this can be source controlled and also act as documentation for the infrastructure.
Leave a comment below letting me know your preferred method for resource creation and why, I’d be interested to hear your thoughts on the above.