GitHub Actions Integration
Crust can be easily integrated into your GitHub Actions workflow to automatically analyze your Terraform PRs. This section explains how to set up this integration.Overview
The GitHub Actions integration allows you to:- Run security analysis automatically on each PR
- Calculate infrastructure costs for proposed changes
- Get clear explanations of changes in the PR
- Receive automatic comments with the results
Basic Setup
To get started, create a.github/workflows/crust-analysis.yml file in your repository:
Required Permissions
The workflow requires the following permissions for theGITHUB_TOKEN:
pull-requests: write: Required to create comments on pull requestscontents: read: Required to read repository contents
permissions block at the job level:
Required Configuration
The following options are required for all Crust commands:--openai-api-key: Your OpenAI API key--terraform-plan-command: The command to execute terraform plan
--language: Language for the analysis (defaults to “en”)
Secrets Configuration
You’ll need to configure the following secrets in your repository:OPENAI_API_KEY: Your OpenAI API keyGITHUB_TOKEN: This is automatically provided by GitHub Actions
- Go to your repository settings
- Navigate to “Secrets and variables” > “Actions”
- Click “New repository secret”
- Add each secret with its corresponding value
Customization
You can customize the workflow in several ways:Selective Analysis
To run only specific analyses:Language Configuration
To set the analysis language (optional):Custom Terraform Command
To use a specific Terraform command:Best Practices
- Run on PRs: Configure to run on PRs for early feedback
- Use secrets: Never expose your API keys in code
- Customize format: Adjust comment format as needed
- Monitor costs: Remember that each run uses OpenAI tokens
- Set minimal permissions: Only grant the permissions needed for the workflow to function
- Use command options: Always pass configuration via command options (—option) rather than environment variables
- Always provide required options: Make sure to include both
--openai-api-keyand--terraform-plan-commandin all commands
Example Output
The PR comment will have this format:Troubleshooting
If you encounter issues:- Check GitHub Actions logs
- Verify secrets are configured correctly
- Ensure Terraform command is working
- Confirm OpenAI key is valid
- Verify GITHUB_TOKEN permissions are set correctly
- Make sure you’re using command options (—option) instead of environment variables
- Verify that both required options (
--openai-api-keyand--terraform-plan-command) are provided - If using a container, verify it has all required dependencies
- Check if Node.js and npm are properly installed
- Verify that the environment has access to all required resources