Azure Bicep "Deployment failed ... InvalidTemplate" in CI
Bicep compiled successfully, but Azure Resource Manager rejected the resulting ARM template at deploy time. InvalidTemplate points at a runtime template problem: a bad expression, an unresolved reference, or an invalid property value.
What this error means
az deployment fails with "Deployment failed. ... Code: InvalidTemplate" and a message like "Unable to evaluate template language function" or "The template resource ... is not valid".
ERROR: {"code": "InvalidTemplate", "message": "Deployment template validation failed:
'The template resource 'app' at line '1' and column '...' is not valid: Unable to
evaluate template language function 'resourceId'..."}Common causes
An expression cannot be evaluated at deploy
A function like resourceId or reference is called with wrong arguments, so ARM cannot resolve it even though Bicep compiled.
An invalid property value or missing parameter
A required parameter is unset, or a property value violates the resource schema, which ARM only validates at deploy time.
How to fix it
Validate the deployment first
- Run
az deployment group validateto surface the InvalidTemplate detail without deploying. - Fix the named expression, parameter, or property.
- Re-run the deploy once validation passes.
az deployment group validate -g my-rg \
--template-file main.bicep --parameters @params.jsonInspect the compiled ARM JSON
Build the Bicep to ARM and review the expression ARM rejected; correct the function arguments or parameter wiring in the .bicep source.
az bicep build --file main.bicep --stdoutHow to prevent it
- Run
az deployment group validatein CI before the real deploy. - Pass all required parameters explicitly.
- Use what-if to preview changes and catch template errors early.