Skip to content

Use valid registry names#

Operational Excellence · Container Registry · Rule · 2020_06

Container registry names should meet naming requirements.

Description#

When naming Azure resources, resource names must meet service requirements. The requirements for container registry names are:

  • Between 5 and 50 characters long.
  • Alphanumerics.
  • Container registry names must be globally unique.

Recommendation#

Consider using names that meet container registry naming requirements. Additionally consider naming resources with a standard naming convention.

Examples#

Configure with Azure template#

To deploy registries that pass this rule, consider:

  • Configuring a minLength and maxLength constraint for the resource name parameter.
  • Optionally, you could also use a uniqueString() function to generate a unique name.

For example:

Azure Template snippet
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "name": {
      "type": "string",
      "minLength": 5,
      "maxLength": 50,
      "metadata": {
        "description": "The name of the resource."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "The location resources will be deployed."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.ContainerRegistry/registries",
      "apiVersion": "2023-08-01-preview",
      "name": "[parameters('name')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Premium"
      },
      "identity": {
        "type": "SystemAssigned"
      },
      "properties": {
        "adminUserEnabled": false,
        "policies": {
          "trustPolicy": {
            "status": "enabled",
            "type": "Notary"
          },
          "retentionPolicy": {
            "days": 30,
            "status": "enabled"
          }
        }
      }
    }
  ]
}

Configure with Bicep#

To deploy registries that pass this rule, consider:

  • Configuring a minLength and maxLength constraint for the resource name parameter.
  • Optionally, you could also use a uniqueString() function to generate a unique name.

For example:

Azure Bicep snippet
@minLength(5)
@maxLength(50)
@sys.description('The name of the resource.')
param name string

@sys.description('The location resources will be deployed.')
param location string = resourceGroup().location

resource registry 'Microsoft.ContainerRegistry/registries@2023-08-01-preview' = {
  name: name
  location: location
  sku: {
    name: 'Premium'
  }
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    adminUserEnabled: false
    policies: {
      trustPolicy: {
        status: 'enabled'
        type: 'Notary'
      }
      retentionPolicy: {
        days: 30
        status: 'enabled'
      }
    }
  }
}

Notes#

This rule does not check if container registry names are unique.

Comments