• Azure Resource Namer tool

    If you host anything in Azure, then you’ve probably had to think about resource naming conventions, even if your convention is not to have one! But any time you start building up a sizable collection of resources, having a naming convention can make it a lot easier to manage.

    Microsoft have a suggested convention as part of their Cloud Adoption Framework. It’s pretty straightforward, and makes use of their list of recommended abbreviations for resource types.

    I thought I’d have a go making a simple tool that could automate generating the name. There’s lots of ways I could have built such a tool, but I figured a simple web page should be achievable and make it accessible to most people.

    Most of my time is spent working on back-end code, so here was a chance to play around with a frontend framework. I could have chosen one of the big names, but there’s one I’ve been keeping a keen eye on for a long time that I hadn’t ever actually used - Aurelia - and this seemed like a nice opportunity to kick the tyres. I was really pleased with the result. This is not a complicated web application, but I do like the way Aurelia works. I used Aurelia v1, but I’ll be keen to upgrade to v2 (it’s currently in alpha).

    You can try out the tool at https://david.gardiner.net.au/azure-resource-namer/, with the source code at https://github.com/flcdrg/azure-resource-namer. I made use of GitHub Pages for the publishing part. Later on I might get a custom domain and maybe run it with something like Azure Static Web Apps, but this does the job for now.

    Screenshot

    The naming convention consists of concatenating a number of fields together:

    • The Resource Type and Region fields are drop-down lists.
    • The Workload and Environment fields are user-editable. The type of resource will determine what characters are allowed here.
    • The Instance field is numeric. If you set it to zero then it will be excluded.

    There are a lot of different resource types. The tool supports all the types listed in the previously mentioned abbreviations page. I’m slowly adding extra validation information for each resource, so that you get extra hints should you use an invalid character, the name ends up being too long, and also where there are particular formatting requirements (eg storage accounts).

    Screenshot of invalid character

    Screenshot of invalid too long

    The resource types are listed in resources.ts. For example here’s how the rules and information for the ‘Resource Group’ resource type has been defined:

    {
        abbrev: 'rg',
        name: 'Resource group',
        minLength: 1,
        maxLength: 90,
        // https://docs.microsoft.com/en-us/rest/api/resources/resource-groups/create-or-update#uri-parameters
        regex: /^[-\w\._\(\)]+$/,
        description: 'Alphanumerics, underscores, parentheses, hyphens, periods, and unicode characters that match the regex documentation. Can\'t end with period.'
    }
    

    Once I’ve got all the resource type rules done, there’s probably scope for more customisation options and other enhancements. I’ve already had one of my SixPivot colleagues Dylan contribute the ‘copy to clipboard’ button.

    Give it a try and let me know what you think in the comments. If you’ve got some ideas or would like to contribute additional features, head over to the repo!

  • STEPtember 2021

    STEPtember logo

    It’s the last day of September and also the last day of “STEPtember”!

    STEPtember is a fundraiser to support people with, and research into cerebral palsy. Participants are asked to take at least 10,000 steps each day of the month of September.

    I found out about STEPtember through my colleagues at SixPivot, and signed up with a team to participate this year. Since I’ve been working from home I do try and take a regular morning walk before starting work - but I found that I needed to do a bit more than that (like cycling, gardening or other kinds of exercise) to make it over the 10,000 threshold. I do hope the extra steps are benefiting my health, as well as any donations going to a great cause.

    If you’d like to sponsor me to help me get to my individual fundraising target, head over to my STEPtember profile page (donations are tax deductible for Australians).

  • Azure Functions - Enable specific functions for debugging

    Azure Functions logo

    I’ve been using Azure Functions quite a bit. Indeed I’ve been recently speaking about them and the new support for .NET 5 and soon .NET 6!

    Today I wanted to debug an Azure Function application, but I didn’t want all of the functions in the application to run (as some of them access resources that I don’t have locally). I discovered that you can add a functions property to your host.json file to list the specific functions that should run.

    eg.

    {
      "version": "2.0",
      "functions": [
        "function1",
        "function2"
      ]
    }
    

    But I really would prefer not to edit host.json as that file is under source control and I’d then need to remember to not commit those changes. I’d much prefer not to have to remember too many things!

    There’s a section in the documentation that describes how you can also set these values in your local.settings.json (which isn’t usually under source control). But the examples given are for simple boolean properties. How do you enter the array value?

    To find out, I temporarily set the values in host.json and used the IConfigurationRoot.GetDebugView() extension method to dump out all the configuration to see how they were represented.

    Here’s the answer:

    {
        "Values": {
            "AzureFunctionsJobHost__functions__0": "function1",
            "AzureFunctionsJobHost__functions__1": "function2"
        }
    }
    

    The __0 and __1 represent each element in the array. With that in place when I run the Azure Function locally, only function and function2 will run. All others will be ignored. Just add additional properties (incrementing the number) to enable more functions.