Deploying a Virtual Machine in Azure Using an ARM Template

Deploying a Virtual Machine in Azure Using an ARM Template: A Step-by-Step Guide

Azure Resource Manager (ARM) templates are a powerful way to deploy and manage resources in Microsoft Azure. This blog will walk you through the process of depl…


This content originally appeared on DEV Community and was authored by Tracy Chinedu

Deploying a Virtual Machine in Azure Using an ARM Template: A Step-by-Step Guide

Azure Resource Manager (ARM) templates are a powerful way to deploy and manage resources in Microsoft Azure. This blog will walk you through the process of deploying a virtual machine (VM) in Azure using an ARM template directly from the Azure Portal. This approach simplifies the deployment of complex environments and ensures consistency.

Step 1: Prepare Your ARM Template

Before you start the deployment process, you need to have your ARM template ready. Here’s a basic example of an ARM template for deploying a Windows VM:

{
  "$schema": "https://schema.management.azure.com/2020-06-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.Compute/virtualMachines",
      "apiVersion": "2023-03-01",
      "name": "[variables('vmName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "hardwareProfile": {
          "vmSize": "Standard_DS1_v2"
        },
        "storageProfile": {
          "imageReference": {
            "publisher": "MicrosoftWindowsServer",
            "offer": "WindowsServer",
            "sku": "2019-Datacenter",
            "version": "latest"
          },
          "osDisk": {
            "createOption": "FromImage",
            "managedDisk": {
              "storageAccountType": "Standard_LRS"
            }
          }
        },
        "osProfile": {
          "computerName": "[variables('vmName')]",
          "adminUsername": "azureuser",
          "adminPassword": "P@ssw0rd1234"
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
            }
          ]
        },
        "diagnosticsProfile": {
          "bootDiagnostics": {
            "enabled": true,
            "storageUri": "[reference(variables('storageAccountId')).primaryEndpoints.blob]"
          }
        }
      }
    },
    {
      "type": "Microsoft.Network/networkInterfaces",
      "apiVersion": "2023-03-01",
      "name": "[variables('nicName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "privateIPAllocationMethod": "Dynamic",
              "publicIPAddress": {
                "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]"
              }
            }
          }
        ]
      }
    },
    {
      "type": "Microsoft.Network/publicIPAddresses",
      "apiVersion": "2023-03-01",
      "name": "[variables('publicIPAddressName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "publicIPAllocationMethod": "Dynamic"
      }
    }
  ],
  "variables": {
    "vmName": "myVM",
    "nicName": "myVMNIC",
    "publicIPAddressName": "myVMPublicIP",
    "storageAccountId": "/subscriptions/[subscriptionId]/resourceGroups/[resourceGroupName]/providers/Microsoft.Storage/storageAccounts/[storageAccountName]"
  }
}

Note: Customize the variables section with your subscription ID, resource group name, and storage account details.

Step 2: Log in to Azure Portal

  1. Go to the Azure Portal: Open portal.azure.com and log in with your Azure account credentials.

Step 3: Navigate to the Resource Group

  1. Access Resource Groups:
    • In the left-hand menu, click on "Resource groups."
    • Select the resource group where you want to deploy the VM. If you don’t have a resource group, you can create a new one by clicking on "+ Create".

Step 4: Start the Deployment

  1. Create a New Deployment:

    • In the selected resource group, click on "Deployments" in the left-hand menu.
    • Click on "+ Create" (or "Add" in some versions).
  2. Select Template Deployment:

    • In the "Search the Marketplace" box, type "Template deployment" and select it from the list.
    • Click on "Create" to start the template deployment process.

Step 5: Build Your Own Template

  1. Load the Template:

    • On the "Custom deployment" page, click on "Build your own template in the editor."
  2. Paste the ARM Template:

    • In the template editor, either upload your template file or paste your ARM template JSON code directly.
    • Click on "Save" to save your changes and return to the deployment page.

Step 6: Configure Deployment Parameters

  1. Fill Out Parameters:

    • On the "Custom deployment" page, you’ll need to enter the parameters for your template. This includes:
      • Subscription: Select the Azure subscription you want to use.
      • Resource group: Choose the existing resource group or create a new one.
      • Region: Ensure the region is correct.
      • Template Parameters: If your template includes parameters, provide the required values (e.g., VM name, admin username, etc.).
  2. Review and Create:

    • Click on "Review + create" to review your deployment settings.
    • Verify that all details are correct.

Step 7: Deploy the Template

  1. Initiate Deployment:

    • Click on "Create" to start the deployment process.
  2. Monitor Deployment:

    • Once you submit, Azure will begin deploying the resources defined in your ARM template.
    • You can monitor the deployment progress in the "Deployments" section of your resource group. Here you can view the deployment status and any errors that might occur.

Step 8: Verify the Deployment

  1. Check Resources:

    • After the deployment is complete, go to the "Virtual machines" section in the Azure Portal.
    • You should see your new VM listed there.
  2. Connect to the VM:

    • Click on the VM to view its details.
    • Use the public IP address to connect to the VM via Remote Desktop (for Windows) or SSH (for Linux).

Conclusion

Deploying a VM using an ARM template through the Azure Portal provides a seamless way to automate and standardize your deployments. By following these steps, you can quickly spin up virtual machines with a consistent configuration, saving time and reducing the potential for errors. For more complex scenarios, you can enhance your ARM template with additional resources and configurations to fit your needs.


This content originally appeared on DEV Community and was authored by Tracy Chinedu


Print Share Comment Cite Upload Translate Updates
APA

Tracy Chinedu | Sciencx (2024-08-14T22:14:07+00:00) Deploying a Virtual Machine in Azure Using an ARM Template. Retrieved from https://www.scien.cx/2024/08/14/deploying-a-virtual-machine-in-azure-using-an-arm-template/

MLA
" » Deploying a Virtual Machine in Azure Using an ARM Template." Tracy Chinedu | Sciencx - Wednesday August 14, 2024, https://www.scien.cx/2024/08/14/deploying-a-virtual-machine-in-azure-using-an-arm-template/
HARVARD
Tracy Chinedu | Sciencx Wednesday August 14, 2024 » Deploying a Virtual Machine in Azure Using an ARM Template., viewed ,<https://www.scien.cx/2024/08/14/deploying-a-virtual-machine-in-azure-using-an-arm-template/>
VANCOUVER
Tracy Chinedu | Sciencx - » Deploying a Virtual Machine in Azure Using an ARM Template. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/14/deploying-a-virtual-machine-in-azure-using-an-arm-template/
CHICAGO
" » Deploying a Virtual Machine in Azure Using an ARM Template." Tracy Chinedu | Sciencx - Accessed . https://www.scien.cx/2024/08/14/deploying-a-virtual-machine-in-azure-using-an-arm-template/
IEEE
" » Deploying a Virtual Machine in Azure Using an ARM Template." Tracy Chinedu | Sciencx [Online]. Available: https://www.scien.cx/2024/08/14/deploying-a-virtual-machine-in-azure-using-an-arm-template/. [Accessed: ]
rf:citation
» Deploying a Virtual Machine in Azure Using an ARM Template | Tracy Chinedu | Sciencx | https://www.scien.cx/2024/08/14/deploying-a-virtual-machine-in-azure-using-an-arm-template/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.