Invalid ARM template due to child resources having "/" in their name

Dilyan Borisov 0 Reputation points
2024-12-17T11:31:48.7+00:00

I get the Resource Group deployment template from the portal (copy/paste) or from the CLI:

az group export --name {source_resource_group_name} --include-comments --include-parameter-default-value --output json

Later, I cannot create resources using this template neither from the portal, nor from the CLI:

az deployment group validate --resource-group {target_resource_group_name} --template-file {arm_file_path} --parameters ...
az deployment group create --name {deployment_name} --resource-group {target_resource_group_name} --template-file {arm_file_path} --parameters ...

I get this error:

{
    "code": "Resource has invalid name",
    "message": "Resource has invalid name Microsoft.Audio. Characters /, \\, ?, #, [, ],  , ., @, %, &, *, (, ), +, =, ;, :, ,, <, > are not allowed."
}

...because some resources related to the OpenAI or KeyVault have names like:

    {
      "type": "Microsoft.KeyVault/vaults/secrets",
      "apiVersion": "2024-04-01-preview",
      "name": "[concat(parameters('vaults_kv_my_random_keyvault_name'), '/my-random-secret')]",
      "location": "swedencentral",
      "dependsOn": [
        "[resourceId('Microsoft.KeyVault/vaults', parameters('vaults_kv_my_random_keyvault_name'))]"
      ],
      "properties": {
        "attributes": {
          "enabled": true
        }
      }
    }

All the resources (including the child ones) within the exported template are at root level (not nested).

Obviously the "/" in the name is needed for validation against the type. Replacing the "/" with the encoded/escaped value "%2F" or the expression uriComponent('/') doesn't help. Removing the "/" it says:

{
    "code": "InvalidTemplate",
    "message": "Deployment template validation failed: 'The template resource 'my-random-keyvault' for type 'Microsoft.CognitiveServices/accounts/defenderForAISettings' at line '1411' and column '74' has incorrect segment lengths. A nested resource type must have identical number of segments as its resource name. A root resource type must have segment length one greater than its resource name. Please see https://aka.ms/arm-syntax-resources for usage details."
}

The docs also very clearly state that the "/" is valid and indeed required:

So WTF I need to do to resolve this ???

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,539 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.