azureazure-resource-managerazure-deployment

Modify ARM-Template for quick deployment


In my organization, we have quite some ressources in Azure which we want to back up the configuration for. However, we are not reaching a big-enough magnitude or maturity that Iac-solutions like Terraform would be viable for us. So ARM-Templates are okay for us.

I have a powershell script running regularly which exports multiple resource groups of a subscription and pushes them to an Azure DevOps. Everything is working here.

My issue is, i wanted to quickly test a deployment but run into several issues. Eg. one template references VMdiagnostic extensions which do not exist yet. Or it points to a disk in a productive environment which i definetly dont want to use when deplyoing to a TEST-resource group.Example parameters: enter image description here

When it comes to an arm-template of the API-management, this becomes even more complicated.

Ideally, there is a way to clean up / prepare ARM-templates in a way that they are deployable with minimal configuration.

Or i need to manually clean up ARM templates and check for referenced resources, edit them appropiately etc. so the ARM-template can be deployed.

Do any best practices exist here which i can apply on the whole of the ARM templates or do i need to go into detail and edit every template file by hand, depending on the resources associated with it?

Or maybe it would be better here to export resources individually rather than whole resource groups to enable some modularity?


Solution

  • Modify ARM-Template for quick deployment

    As you mentioned the idea of backing up and managing ARM is difficult especially when you are dealing with product resources and dependcies and env-specific configuration.

    In order to have minmal manual intervention while using ARM you should follow the mentioned approaches

    Modularize ARM templates:

    Sectionalizing the resources as per the requirment will definately reduce the complexity.

    The furture info on modularization of resources can be seen in the documentation.

    This will explain about Split the templates into smaller files & use linked templates or nested templates for resources that need to be grouped.

    Parameterization

    Define the parameter based configuration based on env so that dynamic reference is possible with this approach.

    sample JSON

    "parameters": {
      "environment": {
        "type": "string",
        "defaultValue": "TEST"
      },
      "vmName": {
        "type": "string",
        "defaultValue": "[concat('vm-', parameters('environment'))]"
      },
      "diagnosticStorageAccountId": {
        "type": "string",
        "defaultValue": "/subscriptions/YoursubscriptionID/resourceGroups/rgname/providers/Microsoft.Storage/storageAccounts/storageaccountname"
      }
    }
    

    It's always a best practice to validate the deployment before execution

    New-AzResourceGroupDeployment -TemplateFile <template.json> -TemplateParameterFile <parameters.json> -ResourceGroupName <resource_group_name> -Mode Validate

    For more info refer the bicep best pratices doc below

    https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/best-practices

    https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/parameters