Skip to content

Multi-env: warn when affixed resource name would exceed APIM's 80-char limit #226

Description

@petehauge

Context

Follow-on from #132 (multi-environment publish to shared APIM). Surfaced during ApimExpert domain review.

The environment: block validator in src/services/env-mapping-validator.ts correctly checks affix characters ([A-Za-z0-9-] only) but does not validate that namePrefix + canonicalName + nameSuffix stays within APIM's per-type name limits (80 characters for APIs, NamedValues, and most other top-level resources).

Problem

A user with a long organizational prefix and a long canonical name can produce a deployed name that exceeds APIM's limit. The failure surfaces as a cryptic HTTP 400 from the ARM API mid-publish, with no clear indication that the affix is the cause.

Example (hypothetical):

  • namePrefix: "production-us-east-" (19 chars)
  • Canonical name: "enterprise-billing-reconciliation-api" (37 chars)
  • nameSuffix: "-v2-stable" (10 chars)
  • Combined: 66 chars — safe. But narrower margins exist.

Proposed fix

After the existing character-validity check in validateAndBuildEnvMapping, iterate over artifactDescriptors and warn (not error — warn) when a combined name would exceed 80 characters. The data is already in scope:

for (const d of artifactDescriptors) {
  if (d.nameParts.length > 0 && mapping.appliesTo.has(d.type)) {
    const deployedLen = prefix.length + d.nameParts[0]!.length + suffix.length;
    if (deployedLen > 80) {
      logger.warn(
        `[publish] Affixed name "${prefix}${d.nameParts[0]}${suffix}" would be ${deployedLen} chars, ` +
          `exceeding APIM's 80-character resource name limit for ${d.type}.`
      );
    }
  }
}

Acceptance criteria

  • Validator warns (not errors) when any descriptor's deployed name would exceed 80 chars
  • Message includes the offending name, the length, and the resource type
  • Unit test covers: short prefix + long canonical name that crosses threshold; long prefix + short canonical name; safe case (no warning)
  • Considered whether some resource types have stricter limits than 80 (currently a global assumption)

Not doing

  • Not promoting to a hard error — some resource types may tolerate longer names, and users can still publish successfully in some scenarios.
  • Not attempting to truncate or transform names automatically.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureNew capabilityeffort:SSmall effort (< 1 day)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions