|
1 | 1 | # Sentinel GitHub Actions |
2 | 2 |
|
3 | | -These Sentinel GitHub Actions allow you to run `sentinel test` and `fmt` on your pull requests to help you review and validate Sentinel policy changes. |
4 | | - |
5 | | -The recommended workflow for using these actions is in the [Terraform Enterprise Sentinel VCS docs](https://www.terraform.io/docs/enterprise/sentinel/integrate-vcs.html). [tfe-policies-example](https://github.com/hashicorp/tfe-policies-example) includes an example of using these actions in practice. |
6 | | - |
7 | | -## Example |
8 | | - |
9 | | -```hcl |
10 | | -workflow "Sentinel" { |
11 | | - resolves = ["sentinel-test", "sentinel-fmt"] |
12 | | - on = "pull_request" |
13 | | -} |
14 | | -
|
15 | | -action "sentinel-test" { |
16 | | - uses = "hashicorp/sentinel-github-actions/test@master" |
17 | | - secrets = ["GITHUB_TOKEN"] |
18 | | - env = { |
19 | | - STL_ACTION_WORKING_DIR = "." |
20 | | - } |
21 | | -} |
22 | | -
|
23 | | -action "sentinel-fmt" { |
24 | | - uses = "hashicorp/sentinel-github-actions/fmt@v0.1" |
25 | | - secrets = ["GITHUB_TOKEN"] |
26 | | - env = { |
27 | | - TF_ACTION_WORKING_DIR = "." |
28 | | - } |
29 | | -} |
| 3 | +Sentinel GitHub Actions allow you to execute Sentinel commands within GitHub Actions. |
| 4 | + |
| 5 | +The output of the actions can be viewed from the Actions tab in the main repository view. If the actions are executed on a pull request event, a comment may be posted on the pull request. |
| 6 | + |
| 7 | +Sentinel GitHub Actions are a single GitHub Action that executes different Sentinel subcommands depending on the content of the GitHub Actions YAML file. |
| 8 | + |
| 9 | +# Success Criteria |
| 10 | + |
| 11 | +An exit code of `0` is considered a successful execution. |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +The most common workflow is to run `sentinel fmt`, `sentinel test` on all of the Sentinel files in the root of the repository when a pull request is opened or updated. A comment will be posted to the pull request depending on the output of the Sentinel subcommand being executed. This workflow can be configured by adding the following content to the GitHub Actions workflow YAML file. |
| 16 | + |
| 17 | +```yaml |
| 18 | +name: 'Sentinel GitHub Actions' |
| 19 | +on: |
| 20 | + - pull_request |
| 21 | +jobs: |
| 22 | + sentinel: |
| 23 | + name: 'Sentinel' |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: 'Checkout' |
| 27 | + uses: actions/checkout@master |
| 28 | + - name: 'Sentinel Format' |
| 29 | + uses: hashicorp/sentinel-github-actions@master |
| 30 | + with: |
| 31 | + stl_actions_version: 0.14.2 |
| 32 | + stl_actions_subcommand: 'fmt' |
| 33 | + stl_actions_working_dir: '.' |
| 34 | + stl_actions_comment: true |
| 35 | + env: |
| 36 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + - name: 'Sentinel Test' |
| 38 | + uses: hashicorp/sentinel-github-actions@master |
| 39 | + with: |
| 40 | + stl_actions_version: 0.14.2 |
| 41 | + stl_actions_subcommand: 'test' |
| 42 | + stl_actions_working_dir: '.' |
| 43 | + stl_actions_comment: true |
| 44 | + env: |
| 45 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
30 | 46 | ``` |
| 47 | +
|
| 48 | +This was a simplified example showing the basic features of these Sentinel GitHub Actions. |
| 49 | +
|
| 50 | +## Inputs |
| 51 | +
|
| 52 | +Inputs configure Sentinel GitHub Actions to perform different actions. |
| 53 | +
|
| 54 | +* `stl_actions_subcommand` - (Required) The Sentinel subcommand to execute. Valid values are `fmt` and `test`. |
| 55 | +* `stl_actions_version` - (Required) The Sentinel version to install and execute. If set to `latest`, the latest stable version will be used. |
| 56 | +* `stl_actions_comment` - (Optional) Whether or not to comment on GitHub pull requests. Defaults to `true`. |
| 57 | +* `stl_actions_working_dir` - (Optional) The working directory to change into before executing Sentinel subcommands. Defaults to `.` which means use the root of the GitHub repository. |
| 58 | + |
| 59 | +## Outputs |
| 60 | + |
| 61 | +Outputs are used to pass information to subsequent GitHub Actions steps. |
| 62 | + |
| 63 | +* `stl_actions_output` - The Sentinel outputs. |
| 64 | + |
| 65 | +## Secrets |
| 66 | + |
| 67 | +Secrets are similar to inputs except that they are encrypted and only used by GitHub Actions. It's a convenient way to keep sensitive data out of the GitHub Actions workflow YAML file. |
| 68 | + |
| 69 | +* `GITHUB_TOKEN` - (Optional) The GitHub API token used to post comments to pull requests. Not required if the `stl_actions_comment` input is set to `false`. |
| 70 | + |
| 71 | +**WARNING:** These secrets could be exposed if the action is executed on a malicious Sentinel file. To avoid this, it is recommended not to use these Sentinel GitHub Actions on repositories where untrusted users can submit pull requests. |
0 commit comments