Unable to deploy APIM due to incorrect segment lengths Error
I am deploying an existing APIM instance using Bicep template but creating a new Product for a client and also referencing function key (default host key) in APIM bicep. I am using YAML pipeline to deploy APIM bicep but pipeline is failing with following error which I am unable to resolve:
There were errors in your deployment. Error code: InvalidTemplate.
##[error]Deployment template validation failed: 'The template resource '/MasterData-2023-07-12/policy' for type 'Microsoft.ApiManagement/service/apis/policies' at line '1' and column '2241' 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.'.
##[warning]Validation errors were found in the Azure Resource Manager template. This can potentially cause template deployment to fail. Task failed while creating or updating the template deployment.. Please follow https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-syntax
Starting Deployment.
Deployment name is APIM-20250206-100144-0761
There were errors in your deployment. Error code: InvalidTemplate.
##[error]Deployment template validation failed: 'The template resource '/MasterData-2023-07-12/policy' for type 'Microsoft.ApiManagement/service/apis/policies' at line '1' and column '2241' 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.'.
##[error]Check out the troubleshooting guide to see if your issue is addressed: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-resource-group-deployment?view=azure-devops#troubleshooting
##[error]Task failed while creating or updating the template deployment.
I posted this issue in Developer Community for Azure DevOps which can be checked at following link:
https://developercommunity.visualstudio.com/t/The-template-resource-APIM-Policies-has-/10841465
The engineering team from the Developer Community asked me to reach out to Bicep team via https://github.com/Azure/bicep/issues
I posted the same issue to get assistance from Bicep team but no one has responded on my ticket in last 2 days. Ticket can be checked here:
https://github.com/Azure/bicep-types-az/issues/2425
Kindly guide me on how can I get rid of this Invalid Segment Length error. I can share bicep templates in private chat.