Skip to content

feat: add Azure Policy constraint parser#658

Merged
anakrish merged 1 commit intomicrosoft:mainfrom
anakrish:azure-policy-parser
Apr 4, 2026
Merged

feat: add Azure Policy constraint parser#658
anakrish merged 1 commit intomicrosoft:mainfrom
anakrish:azure-policy-parser

Conversation

@anakrish
Copy link
Copy Markdown
Collaborator

@anakrish anakrish commented Apr 3, 2026

Add constraint.rs module that parses Azure Policy JSON constraints into span-annotated AST nodes:

  • Logical combinators: allOf, anyOf, not
  • Leaf conditions: field/value with all 20 operators
  • Count blocks: field-count and value-count with where clauses

Public API: parse_constraint() parses a standalone constraint from JSON.

Includes YAML-driven test suite with 6 test files covering operators, fields, expressions, logical combinators, count, and parse errors.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an Azure Policy constraint parser to the languages::azure_policy::parser module, exposing a public parse_constraint() API that parses the JSON under a policy rule’s "if" into span-annotated AST nodes. It also introduces a YAML-driven integration test suite to validate that a wide variety of constraint shapes can be parsed (and that invalid shapes are rejected).

Changes:

  • Added constraint.rs with parsing for logical combinators (allOf/anyOf/not), leaf conditions (field/value + operator), and count blocks (including where).
  • Exposed parser::parse_constraint() as a public API and added ParseError::DuplicateKey.
  • Added YAML-driven parser integration tests plus duplicate-key regression tests.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/languages/azure_policy/parser/mod.rs Updates module docs and adds the public parse_constraint() entrypoint.
src/languages/azure_policy/parser/constraint.rs New constraint parsing implementation (combinators, leaf conditions, count/where).
src/languages/azure_policy/parser/error.rs Adds ParseError::DuplicateKey and display formatting.
tests/azure_policy/mod.rs Wires the new parser_tests integration test module.
tests/azure_policy/parser_tests/mod.rs New YAML-driven test runner that extracts "if" and calls parse_constraint().
tests/azure_policy/parser_tests/cases/operators.yaml Adds operator-focused parsing cases.
tests/azure_policy/parser_tests/cases/logical_combinators.yaml Adds parsing cases for allOf/anyOf/not nesting.
tests/azure_policy/parser_tests/cases/fields.yaml Adds parsing cases for built-in fields and field-path patterns.
tests/azure_policy/parser_tests/cases/expressions.yaml Adds parsing cases for ARM template expressions in constraint positions.
tests/azure_policy/parser_tests/cases/count.yaml Adds parsing cases for count (field/value) and nested where constraints.
tests/azure_policy/parser_tests/cases/parse_errors.yaml Adds malformed/invalid JSON/constraint shapes expected to fail parsing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Add constraint.rs module that parses Azure Policy JSON constraints
into span-annotated AST nodes:

- Logical combinators: allOf, anyOf, not
- Leaf conditions: field/value with all 19 operators
- Count blocks: field-count and value-count with where clauses

Public API: parse_constraint() parses a standalone constraint from JSON.

Includes YAML-driven test suite with 6 test files covering operators,
fields, expressions, logical combinators, count, and parse errors.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@anakrish anakrish marked this pull request as ready for review April 3, 2026 21:43
@anakrish anakrish merged commit 687be28 into microsoft:main Apr 4, 2026
63 checks passed
@anakrish anakrish deleted the azure-policy-parser branch April 4, 2026 00:10
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