Skip to content

[ARM/Bicep] az deployment: Fix bicep template size inflation causing 4MB limit errors #31989

@vhvb1989

Description

@vhvb1989

Problem

Azure CLI deployments of bicep templates near the 4MB size limit fail with "template too large" errors due to unnecessary size inflation during processing.

Root Cause

The issue occurs because:

  1. JsonCTemplatePolicy string escaping: When processing bicep templates, the CLI converts them to JSON strings and applies JsonCTemplatePolicy, which escapes special characters (quotes, newlines, backslashes)
  2. Size inflation: The escaped JSON strings become significantly larger than the original template content
  3. False 4MB limit errors: Templates under 4MB fail due to the inflated request payload size

Example Impact

A 3.2MB bicep template becomes ~4.1MB after string escaping, causing deployment failures even though the original template is well under the Azure limit.

Current Workaround

Users must manually reduce template size or split into smaller templates, even when the original template is within Azure's limits.

Proposed Solution

Implement differential template handling:

  • Bicep files: Use JSON objects directly (no string escaping/JsonCTemplatePolicy)
  • ARM template files: Continue using string content with JsonCTemplatePolicy
  • URI-based deployments: Use template_link without local processing

This maintains backward compatibility while fixing the size inflation issue for bicep templates.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions