Skip to content

feat: Add support for custom OPA command line arguments#1576

Merged
james00012 merged 4 commits intomainfrom
feat/opa-extra-args
Aug 29, 2025
Merged

feat: Add support for custom OPA command line arguments#1576
james00012 merged 4 commits intomainfrom
feat/opa-extra-args

Conversation

@james00012
Copy link
Copy Markdown
Contributor

@james00012 james00012 commented Jul 26, 2025

Description

This PR adds support for passing custom command-line arguments to OPA eval commands and fixes compatibility with OPA v1.0+.

Key Changes

  1. Added ExtraArgs field to EvalOptions

    • Allows passing custom flags to OPA eval (e.g., --v0-compatible, --format json)
    • Arguments are placed after the eval subcommand and before standard arguments
  2. Fixed OPA v1.0+ compatibility

    • Updated Rego policies to use required if keyword for rule bodies
    • Added contains keyword for partial set rules
    • Created v0-compatible policy for testing with --v0-compatible flag

Why These Changes Were Necessary

  • OPA eval commands sometimes need additional flags (e.g., --v0-compatible for backward compatibility)
  • OPA v1.0+ requires new syntax that wasn't compatible with existing test policies
  • Previously there was no way to pass custom arguments to OPA eval

Note

TestOPAEvalTerraformModuleRemotePolicy may temporarily fail in CI until this PR is merged to main, as it downloads the policy from the main branch which still has the old syntax.

@james00012 james00012 self-assigned this Jul 26, 2025
@james00012
Copy link
Copy Markdown
Contributor Author

Hi @jsok, PTAL

Copy link
Copy Markdown

@jsok jsok left a comment

Choose a reason for hiding this comment

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

😍 appreciate it!

@james00012
Copy link
Copy Markdown
Contributor Author

Thanks for your patience @jsok, this should be ready for review again.

Copy link
Copy Markdown

@jsok jsok left a comment

Choose a reason for hiding this comment

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

Love the tests and examples, nice work

@james00012 james00012 force-pushed the feat/opa-extra-args branch 2 times, most recently from e8262b7 to 7bfbf3d Compare August 11, 2025 12:34
…tibility

- Add ExtraArgs field to EvalOptions to pass custom flags to OPA eval
- ExtraArgs are placed after 'eval' subcommand (OPA has no true global flags)
- Update Rego policies for OPA v1.0+ syntax (if keyword, contains keyword)
- Create v0-compatible policy for testing with --v0-compatible flag
- Add TestOPAEvalTerraformModuleWithExtraArgs to verify functionality
- Update documentation to explain ExtraArgs usage

Note: TestOPAEvalTerraformModuleRemotePolicy may temporarily fail until merged to main
@james00012 james00012 force-pushed the feat/opa-extra-args branch from 7bfbf3d to c08feb4 Compare August 11, 2025 12:43
- Fixed Rego v1.0 syntax errors in test policies (allow := true if)
- Upgraded CI OPA version from v0.33.1 to v1.1.0 to support --v0-compatible flag
- Removed version detection from ExtraArgs test since CI now uses OPA v1.1.0
- Added skip condition to remote policy test due to syntax mismatch
- Updated policy documentation for version compatibility
denis256
denis256 previously approved these changes Aug 21, 2025
@denis256
Copy link
Copy Markdown
Member

Looks ok, but the code needs to be cleaned:

pre-commit installed at .git/hooks/pre-commit
[INFO] Initializing environment for https://github.com/gruntwork-io/pre-commit.
goimports................................................................Failed
- hook id: goimports
- files were modified by this hook

modules/terragrunt/cmd.go
modules/terragrunt/stack_clean.go
modules/terragrunt/cmd.go

@james00012 james00012 merged commit 6765b93 into main Aug 29, 2025
2 of 3 checks passed
@james00012 james00012 deleted the feat/opa-extra-args branch August 29, 2025 03:34
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