Resources
Resources can follow a similar naming convention to resource groups. Let's verify the following samples:
<service>-<location>
<product>-<location>-<environment>-<service>
<company>-<location>-<environment>-<product>-<service>
Depending on your needs, you may require different data to be available. In general, you can implement the following two approaches:
- Each element has to be as verbose as possible.
- A child element only has to implement the extra information that is not available for the parent.
Here are examples of those two approaches:
TheCloudTheory-IT-Prod -> TheCloudTheory-SomeProduct-Use-Prod-Rg -> TheCloudTheory-SomeProduct-Use-Prod-AppServicePlan
TheCloudTheory-IT-Prod -> SomeProduct-Use-Prod-Rg -> AppServicePlan
The choice is yours – you have to select an approach that meets your requirements when it comes to administering resources in Azure.
Enforcing a naming convention without automating any action may be quite cumbersome. Fortunately, you can easily prepare a script that will tell you what resources do not match the rules. The following is a simple PowerShell script that displays all the resource groups that do not follow the <product>-<location>-<service> convention:
$resources = Get-AzureRmResource
foreach($resource in $resources)
{
$resourceName = $resource.Name
$match = $resourceName -match '[a-z]{1,}-[a-z]{1,3}-[a-z]{1,}'
if($match -eq $false)
{
Write-Host $resourceName
}
}
The preceding script iterates over all the resources inside a subscription and checks whether their names match the regular expression reflecting the expected naming convention. Now, let's say I have the following resource groups:
azure-administrator-logic
azureadministratorarm
azureadministratorarm2
azureadministratoreg
azurequeues
azureadministrator-euw-logicapp
limitsandquotas
uytgu2hddgsxistandardsa
The only one that follows the convention is azureadministrator-euw-logicapp – the rest are invalid and will be displayed.
Once you have your script ready, you can execute it any time you want. What's more is that you do not have to use PowerShell – you can leverage the Azure CLI or the REST API of the Azure Resource Manager to implement this functionality using other programming languages. Now that we've covered Azure Logic Apps, you can even implement your own pipeline integrated with Azure Event Grid, which will allow you to verify each resource once it has been provisioned.
For more information about naming conventions, refer to the following link: https://docs.microsoft.com/en-us/azure/architecture/best-practices/naming-conventions.