Knight Talks Tech

Create a new Resource Group

Azure Resource Group

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:

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:

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:

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.

Exit mobile version