Invalid ARM template due to nested resources having “/” in their name

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:

  • https://learn.microsoft.com/en-us/azure/azure-resource-manager/troubleshooting/error-invalid-name-segments?tabs=json
  • https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/child-resource-name-type

So what do I need to do to resolve this?

4

It is possible that the exported templates fail the provision of redeploying it though the exported template is valid Json.

According to the given MS Doc, there are some limitations given here when it comes to exporting and redeploying the templates.

Export is not guaranteed to succeed. Check your exported template to make sure it includes the properties you need. If necessary, edit the exported template.

So, it means that you need to verify the template first before redeploying it and add the missing or necessary properties or changes to deploy it successfully.

Referring to az group export command, I have exported the existed key vault template in the below way as shown and was succeeded saving it to the output Json file exportedtemplate.json.

keyvaultID=$(az resource show --resource-group caronew --name carokeyv --resource-type Microsoft.keyvault/vaults --query id --output tsv)
az group export --resource-group caronew --resource-ids $keyvaultID > exportedtemplate.json

After exporting it to the console, I have tried to redeploy it to another resource group according to your requirement, but it failed with some error called “Parameter value not specified”.

Then I compared the sample key vault and secret ARM template from MSDoc with the generated exported template and made few changes to run it successfully. I was able to redeploy it to another resource group without any conflict.

az deployment group create --resource-group pyrgp --template-file exportedtemplate.json

Recognized by Microsoft Azure Collective

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật