Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Azure resource group deployments with ARM JSON templates in Subscription with PowerShell

In this article, this example shows how to deploy resource group in Azure subscription. While deploying resource group with PowerShell you need to use New-AzSubscriptionDeployment cmdlet. Below is the output after deploying Resource Group in the subscription.

.\091-Complete_ARM_Template> # Create a hashtable for parameters
$templateParameters = @{
    rgLocation = 'eastus'
    rgName     = 'test'
}

# Set the location where the template file is stored
$templateFilePath = '.\resource_group.json'

# Deploy the ARM template
New-AzSubscriptionDeployment `
    -Location $templateParameters.rgLocation `
    -TemplateFile $templateFilePath `
    -TemplateParameterObject $templateParameters

Id                      : /subscriptions/9exxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/providers/Microsoft.Resources/deployments/resource_group
DeploymentName          : resource_group
Location                : eastus
ProvisioningState       : Succeeded
Timestamp               : 17-10-2024 01:59:45
Mode                    : Incremental
TemplateLink            : 
Parameters              : 
                          Name             Type                       Value
                          ===============  =========================  ==========
                          rgLocation       String                     "eastus"
                          rgName           String                     "test"
                          tags             Object                     {"Environment":"Dev","Project":"Tutorial"}

Outputs                 : 
DeploymentDebugLogLevel : 

Here is actual ARM json template, it is as same as other Azure resources ARM templates. Only while deploying it with PowerShell or Azure CLI method is little different as shown.

Download this script resource_group_azure_ARM_template_PowerShell.zip here or it is also available on github.com.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "rgLocation": {
            "type": "string",
            "defaultValue": "eastus"
        },
        "rgName": {
            "type": "string",
            "defaultValue": "myResourceGroup"
        },
        "tags": {
            "type": "object",
            "defaultValue": {
                "Environment": "Dev",
                "Project": "Tutorial"
            }
        }
    },
    "resources": [
        {
            "type": "Microsoft.Resources/resourceGroups",
            "apiVersion": "2018-05-01",
            "location": "[parameters('rgLocation')]",
            "name": "[parameters('rgName')]",
            "tags": "[parameters('tags')]"
        }
    ]
}

Below is the way you can deploy resource group using azurecli (az cli). More about 

For more on Subscription ARM templates check
https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/deploy-to-subscription?tabs=azure-cli
https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/deploy-to-resource-group?tabs=azure-cli

# Define variables for deployment
rgLocation="eastus"
rgName="test"

# Set the path to the template file
templateFilePath="./resource_group.json"

# Deploy the ARM template
az deployment sub create \
  --location $rgLocation \
  --template-file $templateFilePath \
  --parameters rgLocation=$rgLocation rgName=$rgName

Related article 
Configure CPU quota usage alerts for subscription using Azure Bicep templates
Create CPU quota usage alerts for subscription using Azure ARM templates
Deploy CPU quota usage alerts for subscription using Terraform azapi provider
Microsoft Azure Virtual WAN Part 1 - Create Virtual Network and subnets
Part 2 Create a Virtual WAN (VWAN) on Azure Portal
Microsoft Azure Virtual WAN Part 3 - Create secured virtual hub inside VWAN
Microsoft Azure Virtual WAN Part 3.1 - Create secured virtual hub inside Azure Firewall Manager
Microsoft Azure Virtual WAN Part 4 - Add Virtual Network connection | Hub vNet Peering
Microsoft Azure Virtual WAN Part 5 - Create Azure Virtual Machine (VM)
Microsoft Azure Virtual WAN Part 6 - Creating and configuring Azure Firewall Policies
Microsoft Azure Virtual WAN Part 7 - Configure security configuration | Route traffic to your secured hub | Test connectivity
Using terraform to clone a virtual machine on VMware vSphere infrastructure
Terraform module clone VMware vSphere Linux and Windows virtual machine
Terraform VMware vSphere Virtual Machine customization clone failed on Windows
Terraform VMware vSphere Virtual Machine cloning Operating system not found

Go Back

Comment

Blog Search

Page Views

12146602

Follow me on Blogarama