Scroll to top
© 2024, Global Digital Services LLC.

Automating Cost-Saving Policies in Azure using ARM


Fernando Noguera - December 7, 2023 - 0 comments

In this blog post, we’ll explore how to use ARM templates to implement cost-saving measures in Azure.

What is an ARM template?

Azure Resource Manager (ARM) templates are JSON files that define the resources you need to deploy for your solution. By using ARM templates, you can define your infrastructure as code, making your configurations repeatable and declarative.

Let’s create an Azure Resource Manager (ARM) template for a demonstration, showcasing the straightforward deployment of Azure resources.

Automate Cost Savings with ARM Templates

1. Define Your ARM Template: first, create a new file named cost-saving-template.json. This will be our main ARM template file.

2. Use Low-Cost SKUs: If you’re deploying resources like virtual machines, databases, or others, you can choose lower-cost SKUs (stock keeping units).

{
  "resources": [
    {
      "type": "Microsoft.Compute/virtualMachines",
      "apiVersion": "2020-06-01",
      "name": "costEffectiveVM",
      "location": "[resourceGroup().location]",
      "sku": {
        "name": "Standard_B1s" // This is one of the burstable VMs which is cheaper
      }
      // ... rest of the VM properties
    }
  ]
}

3. Implement Auto-Shutdown for VMs: Auto-shutdown can be set for VMs to ensure they’re not running and incurring costs when not needed.

{
  "resources": [
    {
      "type": "Microsoft.DevTestLab/schedules",
      "name": "shutdown-computevm",
      "apiVersion": "2018-09-15",
      "properties": {
        "status": "Enabled",
        "taskType": "ComputeVmShutdownTask",
        "dailyRecurrence": {
          "time": "1900" // This is 7 PM UTC
        },
        "timeZoneId": "UTC",
        "targetResourceId": "[resourceId('Microsoft.Compute/virtualMachines', 'costEffectiveVM')]"
      }
    }
  ]
}

4. Enable Budgets and Alerts: It’s possible to set budgets on your resources or resource groups and get alerted when the consumption approaches or exceeds the budget.

{
  "resources": [
    {
      "type": "Microsoft.Consumption/budgets",
      "apiVersion": "2019-10-01",
      "name": "monthlyBudget",
      "properties": {
        "category": "Cost",
        "amount": 100, // Your monthly budget amount in your currency
        "timeGrain": "Monthly",
        "timePeriod": {
          "startDate": "2023-10-01T00:00:00Z",
          "endDate": "2023-11-01T00:00:00Z"
        },
        "notifications": {
          "nearBudget": {
            "enabled": true,
            "operator": "GreaterThanOrEqualTo",
            "threshold": 90, // Notify when 90% of budget is reached
            "contactEmails": ["youremail@example.com"] // Add more emails as needed
          }
        }
      }
    }
  ]
}

5. Deploy the ARM Template: To deploy your ARM template, you can use the Azure CLI:

az group deployment create --resource-group <Your-Resource-Group-Name> --template-file cost-saving-template.json

ARM templates offer a powerful way to automate cost-saving policies in Azure. By defining your infrastructure as code, you can ensure consistency, reduce manual errors, and enforce best practices to keep your Azure bill in check.

At GDS IT Consulting Services, our team of skilled cloud engineers and architects is ready to help you optimize your cloud infrastructure on Azure.

Contact us for more information or visit our blog.

Related posts