官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 岳阳县| 海丰县| 惠安县| 威海市| 图片| 共和县| 浦北县| 林州市| 东阿县| 崇仁县| 铜山县| 洪雅县| 山阴县| 宜兰县| 渑池县| 河曲县| 樟树市| 百色市| 志丹县| 开原市| 格尔木市| 安丘市| 巴南区| 凯里市| 平利县| 无棣县| 三门县| 五家渠市| 托克托县| 五河县| 泰州市| 霍林郭勒市| 鹤峰县| 东方市| 莆田市| 南投市| 大足县| 华安县| 靖边县| 灌南县| 青海省|