Syntax Highlighter

martes, 1 de agosto de 2017

Some time back while preparing the Global Azure Bootcamp Science Lab, I face the lack of some functions that are not available when authoring Azure Resource Manager templates. When creating some type of resources such as Batch jobs or RBAC related resources, you need to pass a GUID (Universally unique identifier) but there is no function to create them inside the template, so you need to pass them as template parameters making the result awful.

When trying to provide a workaround, I finally found that could be solved with nested templates, so I started by building a simple ARM Guid template that could be referenced on your primary one. You can check that repo here https://github.com/davidjrh/azurerm-newguid

Building a GUID function for ARM templates with Azure Functions

Revisiting this today, I thought that could be more cost effective of having that dynamically generated template by using an Azure Function. Here is the step by step so you can deploy your own, and increase your ARM functions arsenal with the same approach.

Remember that the basic idea is to reference this function in your deployment, that will generate a GUID for later usage on your template.

// validate the input int guids; if (!int.TryParse(numberOfGuids, out guids)) { return req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a valid number on the query parameter 'numberOfGuids'"); } if (guids <= 0 || guids > 1000) { return req.CreateResponse(HttpStatusCode.BadRequest, $"Invalid number of guids {guids}. Must be a number between 1 and 1000"); }