-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add option allowing usage of custom policy check tools #3765
Merged
GenPage
merged 4 commits into
runatlantis:main
from
bgalkows:bgalkows/custom-policy-check
Oct 6, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b415f30
Adding new flag everywhere relevant, implementing policy result worka…
bgalkows a3270ec
Fixing unit test str matching, adding custom policy conditional to st…
bgalkows d3bc4e3
Adding documentation steps for custom policy tools
bgalkows d29ed31
Refactoring ConftestOutput attribute to PolicyOutput
bgalkows File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Custom Policy Checks | ||
If you want to run custom policy tools or scripts instead of the built-in Conftest integration, you can do so by setting the `custom_policy_check` option and running it in a custom workflow. Note: custom policy tool output is simply parsed for "fail" substrings to determine if the policy set passed. | ||
|
||
This option can be configured either at the server-level in a [repos.yaml config file](server-configuration.md) or at the repo-level in an [atlantis.yaml file.](repo-level-atlantis-yaml.md). | ||
|
||
## Server-side config example | ||
Set the `policy_check` and `custom_policy_check` options to true, and run the custom tool in the policy check steps as seen below. No | ||
|
||
```yaml | ||
repos: | ||
- id: /.*/ | ||
branch: /^main$/ | ||
apply_requirements: [mergeable, undiverged, approved] | ||
policy_check: true | ||
custom_policy_check: true | ||
workflow: custom | ||
workflows: | ||
custom: | ||
policy_check: | ||
steps: | ||
- show | ||
- run: cnspec scan terraform plan $SHOWFILE --policy-bundle example-cnspec-policies.mql.yaml | ||
policies: | ||
owners: | ||
users: | ||
- example_ghuser | ||
policy_sets: | ||
- name: example-set | ||
path: example-cnspec-policies.mql.yaml | ||
source: local | ||
``` | ||
|
||
|
||
## Repo-level atlantis.yaml example | ||
First, you will need to ensure `custom_policy_check` is within the `allowed_overrides` field of the server-side config. Next, just set the custom option to true on the specific project you want as shown in the example `atlantis.yaml` below: | ||
|
||
```yaml | ||
version: 3 | ||
projects: | ||
- name: example | ||
dir: ./example | ||
custom_policy_check: true | ||
autoplan: | ||
when_modified: ["*.tf"] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add an example on how to use this with another tool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jamengual Added
custom-policy-checks.md
with examples for both ways to set the flag and linked to it fromserver-side-repo-config.md