-
Notifications
You must be signed in to change notification settings - Fork 38
feat: Add GH action for VDI module with TF Test #701
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
Conversation
| - name: Terraform fmt | ||
| id: fmt | ||
| run: terraform fmt -check | ||
| continue-on-error: true | ||
|
|
||
| # Initialize a new or existing Terraform working directory | ||
| - name: Terraform Init |
Check failure
Code scanning / CodeQL
Untrusted Checkout TOCTOU Critical
issue_comment
This autofix suggestion was applied.
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To fix the problem, change the checkout step to use an immutable reference (commit SHA) instead of the mutable branch reference. Specifically, replace ref: ${{ steps.comment-branch.outputs.head_ref }} with ref: ${{ steps.comment-branch.outputs.head_sha }} in the checkout step. This ensures that the code being checked out and executed is exactly the commit that was referenced when the workflow was triggered, preventing TOCTOU (Time-of-Check to Time-of-Use) attacks. No other changes are needed, as the rest of the workflow references the commit SHA for status updates and comments.
-
Copy modified line R78
| @@ -75,7 +75,7 @@ | ||
| - name: Checkout PR branch ${{ steps.comment-branch.outputs.head_ref }} | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ steps.comment-branch.outputs.head_ref }} | ||
| ref: ${{ steps.comment-branch.outputs.head_sha }} | ||
| repository: ${{ steps.comment-branch.outputs.head_repo }} | ||
| fetch-depth: 0 | ||
|
|
| - name: Terraform Init | ||
| id: init | ||
| run: terraform init | ||
|
|
||
| # Run the actual Terraform tests | ||
| - name: Terraform Test |
Check failure
Code scanning / CodeQL
Untrusted Checkout TOCTOU Critical
issue_comment
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To fix the problem, ensure that the workflow checks out code using an immutable reference (commit SHA) that is guaranteed to be set by GitHub and not derived from potentially manipulated workflow logic or untrusted input. Specifically, replace the checkout step's ref input with ${{ github.event.pull_request.head.sha }} and the repository input with ${{ github.event.pull_request.head.repo.full_name }}. This ensures that the code being checked out is exactly the code that was reviewed and approved, and cannot be changed after the security check. Only the checkout step needs to be updated; all subsequent steps will operate on the securely checked-out code.
-
Copy modified line R75 -
Copy modified lines R78-R79
| @@ -72,11 +72,11 @@ | ||
| }) | ||
|
|
||
| # Checkout the PR branch | ||
| - name: Checkout PR branch ${{ steps.comment-branch.outputs.head_ref }} | ||
| - name: Checkout PR branch ${{ github.event.pull_request.head.ref }} | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ steps.comment-branch.outputs.head_sha }} | ||
| repository: ${{ steps.comment-branch.outputs.head_repo }} | ||
| ref: ${{ github.event.pull_request.head.sha }} | ||
| repository: ${{ github.event.pull_request.head.repo.full_name }} | ||
| fetch-depth: 0 | ||
|
|
||
| # Use GitHub Action secret to assume existing AWS IAM Role using OIDC connection |
| - name: Terraform Test | ||
| id: test | ||
| run: terraform test | ||
| # run terraform test -filter="tests/<your-desired-test>" | ||
|
|
||
| # 7. Comment on PR the result of the workflow | ||
| - name: Add workflow result as comment on PR |
Check failure
Code scanning / CodeQL
Untrusted Checkout TOCTOU Critical
issue_comment
Copilot Autofix
AI 4 months ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.
…CTOU I am trusting you, AI 🤖 Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
|
I'm a bit confused by this PR. We need to define a new action for each tftest module? I thought we tried to avoid this? |
|
Yeah unfortunately we do right now. I wasn't able to find an easy way to target specific modules since they're all in a central /modules directory. For AWS-IA modules, each module is its own git repo which simplifies tf tests/the gh action. You can just do a simple For the toolkit since we have multiple modules in the same repo, and these are not at the same level (root), we have to change directory into the specific directory to be able to run tests for that individual module. If we have a simple For example: jobs:
terraform-testing:
# TODO: scope these permissions down
permissions: write-all
name: Terraform Testing
# Only run if it is a PR and the comment contains '/run-vdi-module-tf-tests'
if: github.event.issue.pull_request && contains(github.event.comment.body, '/run-vdi-module-tf-tests')
runs-on: ubuntu-latest
environment: aws-ci
defaults:
run:
working-directory: ${{ github.workspace }}/modules/vdi/the Only other thing I could think of is to enforce PRs have the directory name in the title which can be fetched (and maybe have some regex match). Maybe I'm overthinking it. We should hop on a call at some point - I also wanted to tackle the issue of ensuring PRs from forks can also use the actions. |
Issue number:
N/A
Summary
Changes
A new GitHub Actions workflow file
tf-test-on-comment-modules-vdi.ymlwas added to enable on-demand Terraform testing for the VDI module. The workflow is triggered by PR comments containing/run-vdi-module-tf-testsand runs comprehensive Terraform validation including formatting checks, initialization, and test execution with AWS credentials via OIDC.User experience
Before: Developers working on the VDI module had no automated way to run Terraform tests on-demand for their pull requests. Testing would need to be done manually or wait for standard CI/CD pipeline execution.
After: Developers can now trigger VDI module Terraform tests by simply commenting
/run-vdi-module-tf-testson any pull request. The workflow provides real-time feedback through PR comments, showing when tests are scheduled, in progress, and completed with success/failure status and links to the full GitHub Actions run. This currently will only work for PRs submitted from branches of this source repo. Forks are not supported yet, but will be added via #664.Checklist
If your change doesn't seem to apply, please leave them unchecked.
Is this a breaking change?
noAcknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created might not be successful.