Swetha Mudunuri
6 min readFeb 8, 2023

How to create a Resource Group using Azure Portal, Azure CLI, Powershell, and Terraform

🎯What is a resource group?

A resource group is a logical container that holds all the resources. It’s employed to logically aggregate a variety of Azure resources, including virtual machines, VNets, storage accounts, etc., for simple deployment, metering, and access control.

🈚You need an Azure account in order to create a resource group. Visit portal.azure.com to register a free tier account if you don’t already have one.

🈯Let’s create a resource group using the Azure portal.

👉You will see the Azure User Interface (UI) as shown below once you have successfully logged into your Azure account.

Azure Home Page

👉Click on “Create” to create a new resource group.

Resource Group creation

To create a resource group, you’ll need to have a name and location details handy.

Resource Group Creation
Successful creation of a resource group

👉Wow successfully created a resource group 😍.

🎯 Let’s delete the resource group .

👉Go to Resource groups- > select the resource group which was created — — >Click on “Delete resource group”.

Select Delete resource group

👉Confirm the name of the resource group and click “Delete”.

Successfully deleted resource group 😊

👉Successfully deleted the resource group from the Azure portal👏.

🎯Let’s create a resource group using the Azure CLI.

👉Download and run the Azure CLI msi file. Azure CLI is a command line interface that allows users to login into Azure and run administrative commands on the Azure resources. This software integrates with our existing command prompt.

👉Go to Search — Command prompt –Run as Administrator.

👉To login into Azure from a command prompt, enter the command “az login”.

Azure CLI Login

👉Command to create a resource group.

Command Syntax
Successful creation of a resource group

👉Command to list the resource groups, “az group list”.

Available resource groups

👉Successfully created the resource group 😎.

Hurray! its successful 😍

👉Command to delete the resource group and you would be thinking why there is no location 🤔. No need to mention the location as the resource group name is unique irrespective of the region.

Command Syntax
Successful deletion of the resource group

👉Successfully deleted the resource group.

👉Refer to the page if you want to learn more about Azure CLI commands.

🎯Let’s create a resource group using the cloud shell.

👉In the Azure portal and click the Cloud Shell icon. Running the Bash or Powershell shell creates a resource group, storage server, and file server while launching the cloud shell.

Cloud Shell

👉Click on PowerShell and click “show advanced options” to see the resource group ,storage and file server details.

Advanced Settings

👉Successfully created the resource group with a predefined group name.

Successful creation of a resource group

👉You can run Bash or PowerShell when you launch the cloud shell. I choose PowerShell 😍 because I love it.

PowerShell Login Screen

👉Basic PowerShell commands

📌To list the subscription “get-azSubscription

📌To list resource groups -”get-azresourceGroup

📌To create a new resource Group “new-AzResourceGroup -Name ‘xxxxx’ -Location ‘xxxxx’ ”

Successful creation of resource group 😊

📌To delete a resource Group “remove-azresourceGroup cloud-shell-storage-westeurope

Deleted the resource group 😊

👉Successfully deleted the resource group 👏

Delete worked😂

🎯Let’s look at installing PowerShell on our computer and connecting to the Azure account.

👉Check the execution policy on your PowerShell console by using the command “ Get-ExecutionPolicy”, if it’s set to restricted, you need to set it to unrestricted to run scripts.

Command Syntax

👉Check that Azure modules are installed by running the command “Get-Command *az*”.

👉Install the Azure module using an install-module command. allowclobber is used to overwrite the module if it already exists.

Successful installation of the Install Module

👉Once the modules are installed , we can use the same commands that were used for cloud shell.

👉Windows Powershell ISE can be used if scripts need to be run. Can enter multiple commands in the script and execute them.

👉Press F8 to run an individual command, and press F5 to run a script.

Windows PowerShell ISE

🎯Troubleshooting in case you are unable to connect to your Azure account.

👉I tried numerous different methods to connect to my Azure account, but I kept getting errors.

👉Finally, I checked the internet and discovered a solution😍.

My Favourite Troubleshooting 😍

👉Commands to reconnect to your Azure account.

📌Import-Module Az.Accounts

📌Clear-AzContext

📌Connect-AzAccount -Tenant <tenant id>

Refer to the link for the PowerShell Command Reference

Finally, reached the last part.

🎯Let’s create a resource group using Terraform.

👉Go to Extensions and install the Azure Terraform extension.

👉If you want to see a list of the available extensions, enter @installed in the search bar for extensions to see if they have been installed or not.

Installed Extensions

👉Install the Azure CLI and connect to the Azure account.

👉Create a folder for Azure in Visual Studio Code and create a file with the .tf extension.

main.tf

👉Enter the name and location of the resource group.

🎯Terraform commands to execute to create and destroy the resource group

📌terraform init- This command installs plugins for necessary providers and creates a working directory with configuration files.This command needs to be used just once during project initialization.

📌terraform fmt- This command is used to format the configuration files.

📌terraform validate- This command is used for validating the syntax.

📌terraform plan- Run the terraform plan to perform a dry run to see what occurs when the commands are carried out.

📌terraform apply-auto-approve-Apply the changes

📌terraform destroy -Destroy the resources mentioned in the .tf file

📌terraform state list -To verify the resources created.

terraform apply
terraform destroy

👉 Follow me Swetha Mudunuri on LinkedIn, and check my GitHub profile swethamudunuri07

👉 Follow Cloudnloud Tech Community for more information on cloud training and career guidance & CloudnLoud@youtube YouTube channel

Swetha Mudunuri
Swetha Mudunuri

Written by Swetha Mudunuri

Cloud and Cybersecurity Professional

Responses (1)