Creating a Resource Group
A resource group is a logical container for Azure resources. It helps you manage and organize your Azure deployment. You can create resource groups using the Azure portal, Azure CLI, Azure PowerShell, or ARM templates.
Using the Azure CLI
The Azure Command-Line Interface (CLI) provides a quick and efficient way to create resource groups. Make sure you have the Azure CLI installed and are logged in to your Azure account.
az group create --name MyResourceGroup --location "East US"
This command creates a resource group named MyResourceGroup in the East US region.
MyResourceGroup with your desired name and East US with the Azure region where you want to create the resource group.
New-AzResourceGroup -Name "MyResourceGroup" -Location "East US"
This PowerShell command achieves the same outcome as the Bash command above.
Using the Azure Portal
- Navigate to the Azure portal.
- In the search bar, type "Resource groups" and select "Resource groups" from the services list.
- Click the "Create" button.
- On the "Create a resource group" page, fill in the following details:
- Subscription: Select your Azure subscription.
- Resource group: Enter a name for your resource group (e.g.,
MyResourceGroup). - Region: Choose the Azure region where you want to deploy the resource group (e.g.,
East US).
- Click "Review + create".
- Click "Create" to finalize the resource group creation.
Using ARM Templates
You can define resource groups within an Azure Resource Manager (ARM) template for declarative deployment. This is particularly useful for automating infrastructure setup.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"resourceGroupName": {
"type": "string",
"defaultValue": "MyTemplateResourceGroup",
"metadata": {
"description": "Name of the resource group to create."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for the resource group."
}
}
},
"resources": [
{
"type": "Microsoft.Resources/resourceGroups",
"apiVersion": "2021-04-01",
"name": "[parameters('resourceGroupName')]",
"location": "[parameters('location')]",
"tags": {
"environment": "development",
"project": "example"
}
}
],
"outputs": {
"resourceGroupId": {
"type": "string",
"value": "[resourceId('Microsoft.Resources/resourceGroups', parameters('resourceGroupName'))]"
}
}
}
To deploy this template, save it as a .json file and use the Azure CLI or Azure PowerShell:
az deployment group create --resource-group MyExistingResourceGroup --template-file create-rg.json
Note that the ARM template itself defines the resource group creation, so you typically deploy it to an existing resource group or as a subscription-level deployment.
New-AzResourceGroupDeployment -Name "CreateRGDeployment" -ResourceGroupName "MyExistingResourceGroup" -TemplateFile "create-rg.json"
Similar to the CLI, the template defines the resource group to be created.