Skip to content

fix(azure_policy): keep value-count names out of field() resolution - #874

Merged
Anand Krishnamoorthi (anakrish) merged 1 commit into
microsoft:mainfrom
snehabandla:split/azure-policy-value-count-field-collision
Oct 29, 2026
Merged

Anand Krishnamoorthi (anakrish) merged 1 commit into
microsoft:mainfrom
snehabandla:split/azure-policy-value-count-field-collision

Conversation

@snehabandla

Copy link
Copy Markdown
Contributor

Summary

Fixes how a value count's name is resolved (compiler/count.rs resolve_count_binding).

Inside a value count such as count: { value: [...], name: "location", where: ... }, the expression field('location') returned the current loop element instead of the resource's location. The same happened for field conditions whose path equals the count's name, including alias paths and dynamic [if(...)] paths. In Azure Policy a value count's name is only reachable through current(); field() and field conditions always read resource fields. This bug already existed on main.

resolve_count_binding no longer matches field paths against value-count names. Two branches that became unreachable are removed. current() resolution is unchanged.

Testing

  • tests/azure_policy/cases/count.yaml has 30 cases, covering:
    • field('location'), alone and alongside current('location');
    • alias field conditions named like the count;
    • a value count inside existenceCondition;
    • names containing [*];
    • the greater: 0 early exit;
    • [if(...)] field paths;
    • value and field counts nested in each other;
    • current() still returning the element.
  • Every match case fails before the fix. Each has a twin that the pre-fix code answers differently, except three labelled guards for behaviour this change must keep.
  • Two unit tests that asserted the old name matching were replaced.
  • All on Rust 1.95.0:
    • cargo fmt --check;
    • clippy with --all-targets --all-features and with --no-default-features;
    • cargo build --all-targets, cargo test --doc, cargo test;
    • the azure_policy lib and integration tests, plus --test aci, --test kata, and OPA with the tests/opa.passing list (2875/0);
    • cargo xtask test-no-std.

Dependencies: none (based on main).

Inside a value count (`count: { value: [...], name: "location", ... }`),
`field('location')` and `field` conditions on a path equal to the count's
`name` resolved to the loop element instead of the resource field. A value
count's `name` is only reachable through `current()`; `field()` and field
conditions always read resource fields.

`resolve_count_binding` no longer matches field paths against value-count
names, and two branches that became unreachable are removed. `current()`
resolution is unchanged.

Tests cover `field()` and alias field conditions named like the count,
existenceCondition, names containing `[*]`, the `greater: 0` early exit,
`[if(...)]` field paths, nested value/field counts, and `current()` still
returning the element. Each match case has a twin that the pre-fix code
answers differently, except three labelled guards.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the Azure Policy field-resolution change.

No open issues 🎉

What changed in this PR

Fixes Azure Policy field resolution so value-count names no longer shadow resource fields. Named loop elements remain accessible through current(), while field-count binding behavior is preserved.

Changes:

  • Removes value-count name matching from field resolution and related helper branches.
  • Updates unit tests and adds 30 regression cases covering name collisions, nested counts, wildcard and dynamic paths, and related-resource evaluation.
File Description
tests/​azure_policy/​cases/​count.yaml Adds regression cases and guards for unchanged count behavior.
src/​languages/​azure_policy/​compiler/​count.rs Restricts field binding resolution to field counts; updates documentation and unit tests.

Review effort: Balanced

@anakrish
Anand Krishnamoorthi (anakrish) merged commit a31eeb4 into microsoft:main Oct 29, 2026
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants