azure-docs
azure-docs copied to clipboard
Bicep loops only work with values that can be determined at the start of deployment
When trying to loop through some values of a created existing resource, I got the following error:
This expression is being used in the for-expression, which requires a value that can be calculated at the start of the deployment. Properties of [app service] which can be calculated at the start include "apiVersion", "id", "type". Bicep(BCP178)
This limitation is not listed in the documentation.
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: 29aa29b9-d815-0d49-3ae4-dce770899fa4
- Version Independent ID: cbde0a1e-6200-5cf2-55c1-d2fdca115d9d
- Content: Iterative loops in Bicep - Azure Resource Manager
- Content Source: articles/azure-resource-manager/bicep/loops.md
- Service: azure-resource-manager
- Sub-service: bicep
- GitHub Login: @mumian
- Microsoft Alias: jgao
@thisjustin816
Thanks for your feedback! We will investigate and update as appropriate.
@mumian Can you please provide your inputs on this?
@thisjustin816 - Hi Justin, can you share your code?
@thisjustin816 - Hi Justin, can you share your code?
resource portalAppService 'Microsoft.Web/sites@2022-03-01' existing = {
name: appService.name
}
resource apiService 'Microsoft.Web/sites@2022-03-01' existing = {
name: 'api-${resourceNameSuffix}'
}
resource cors 'Microsoft.Web/sites/config@2022-03-01' = {
name: 'web'
parent: apiService
properties: {
cors: {
allowedOrigins: [for hostname in portalAppService.properties.enabledHostNames: 'https://${hostname}']
supportCredentials: true
}
}
}
The deployment is a vue app with an api backend. Both are deployed as app services (in separate deployments/pipelines) to the same resource group. I use a bicep registry module for the app service deployments. I also conditionally apply a custom domain based on environment so I recreate the app service resource after applying the domain so that all hostnames are available and since the app service is abstracted by the module. I'm using this to add CORS entries to the backend app service.
The workaround is to just wrap that resource in a module and pass the hostnames in as a parameter to make it a separate deployment.
@thisjustin816 - thank you . I have created a PR to update the limits - https://github.com/MicrosoftDocs/azure-docs-pr/pull/218298
#please-close