You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reusable GitHub Actions for Terraform workflows. Includes plan, apply, validate, security scanning, cost estimation, and more. Automate your infrastructure deployments with production-ready CI/CD pipelines.
Secure Azure authentication without long-lived secrets
π Plan & Apply
Safe infrastructure changes with plan review and approval gates
π Security Scanning
Integrated tfsec, Checkov, and TFLint for compliance
π° Cost Estimation
Infracost integration for cost visibility
π Metrics & Reporting
Resource inventory, change logs, and dependency graphs
π§ͺ Testing
Terratest integration for infrastructure testing
π Drift Detection
Scheduled detection of infrastructure drift
π Secret Scanning
Detect hardcoded secrets before deployment
π Documentation
Auto-generate terraform-docs
πΎ State Backup & Restore
Automated state file backups with restore capability
π¬ PR Comments
Automatic plan/cost/security summaries on pull requests
π’ Notifications
Slack, Teams, Discord integration
π·οΈ Module Versioning
Semantic versioning for modules
π¨ Policy Checks
OPA/Sentinel policy validation
β‘ Plugin Caching
Faster builds with Terraform plugin caching
π Quick Start
1. Copy the Actions to Your Repository
# Clone this repository
git clone https://github.com/Jamonygr/terraform-github-actions.git
# Copy the .github folder to your Terraform project
cp -r terraform-github-actions/.github your-terraform-project/
2. Set Up Authentication
Option A: OIDC (Recommended) π
Add these Variables to your GitHub repository:
Variable
Description
Required
AZURE_CLIENT_ID
Azure AD Application (Client) ID
β Yes
AZURE_TENANT_ID
Azure AD Tenant ID
β Yes
AZURE_SUBSCRIPTION_ID
Azure Subscription ID
β Yes
USE_OIDC
Set to true
β Yes
Add these Secrets:
Secret
Description
Required
TF_STATE_RG
Terraform state resource group
β Yes
TF_STATE_SA
Terraform state storage account
β Yes
INFRACOST_API_KEY
Infracost API key
β Optional
See SETUP.md for detailed OIDC configuration instructions.
Option B: Service Principal (Legacy)
Add these Secrets to your GitHub repository:
Secret
Description
Required
AZURE_CREDENTIALS
Azure service principal JSON
β Yes
TF_STATE_RG
Terraform state resource group
β Yes
TF_STATE_SA
Terraform state storage account
β Yes
INFRACOST_API_KEY
Infracost API key
β Optional
3. Trigger the Workflow
# Push changes to trigger the pipeline
git add .
git commit -m "Add Terraform GitHub Actions"
git push
π Documentation
Full documentation is available in the repo wiki folder. Start here:
The unified workflow (terraform.yml) supports single, matrix, and drift modes. High-level view:
Stage Details
Stage
Job(s)
Purpose
Notes
0
router
Select mode (single, matrix, drift)
repo-hygiene optional
1
format
Enforce terraform fmt
Blocking
2
validate
Validate configuration
Blocking
3
Security suite
tfsec, Checkov, secret scan, ShellCheck
Terrascan optional
4
Lint and policy
TFLint, policy checks, terraform-docs
Docs check optional
5
Analysis
Graph + module versions
Always on
6
Cost and versions
Infracost + provider checks
Cost is single mode only
7
plan
Plan + PR comment + blast radius
Single mode only
8
apply
Apply in single mode
Auto on push unless AUTO_APPLY=false; environment gates still apply
9
destroy
Manual destroy + confirm
Environment gates
10
metrics
Post-apply reporting
Single mode only
Optional post-plan actions include tag audit, Terratest PR integration tests, ephemeral PR environments, and canary apply. Many stages are gated by mode, event, or repo variables, so plan-only runs will show skipped jobs. See Pipeline Stages for the full list and mode-specific jobs (matrix and drift).
βοΈ Configuration
Workflow Inputs
Input
Description
Default
Options
mode
Pipeline mode
single
single, matrix, drift
environment
Target environment (single mode)
lab
dev, lab, staging, prod
environments
Target environments (matrix mode)
dev,staging,prod
Comma-separated list
action
Pipeline action
plan
plan, apply, destroy
destroy_confirm
Destruction confirmation
-
Type DESTROY
working_directory
Terraform working directory
./test
Any relative path
create_drift_issue
Create GitHub issue on drift
true
true, false
Note: this repository ships a minimal Terraform config in ./test, so the workflow defaults to ./test. Set working_directory to . or your own path (or set TF_WORKING_DIRECTORY) when using your own Terraform layout.
Environment Variables
env:
TF_VERSION: '1.9.0'# Terraform versionENVIRONMENT: 'lab'# Default environmentWORKING_DIRECTORY: './test'# Default for this repo; override as needed
Optional Repository Variables
Variable Name
Description
TF_WORKING_DIRECTORY
Default Terraform working directory (e.g., ./test)
ENABLE_TERRAFORM_TESTS
Set to false to disable terraform test stage
ENABLE_MODULE_CONTRACTS
Enable module contract checks for modules/
FAIL_ON_MODULE_CONTRACTS
Fail pipeline when contract checks find issues
DOCS_ENFORCE
Enforce terraform-docs check (fail on diff)
ENABLE_TERRASCAN
Enable Terrascan security scan
TERRASCAN_VERSION
Override Terrascan version (default 1.18.3)
AUTO_APPLY
Auto-apply on push unless set to false
REQUIRED_TAG_KEYS
Comma-separated required tag keys for tag audit
FAIL_ON_TAG_AUDIT
Fail pipeline when tag audit finds missing tags
ENABLE_CANARY
Enable canary apply before prod
CANARY_ENVIRONMENT
Environment name for canary (e.g., canary)
CANARY_VAR_FILE
Var file for canary (default environments/<env>.tfvars)
CANARY_STATE_KEY
State key for canary (default <env>.terraform.tfstate)
ENABLE_EPHEMERAL_ENV
Enable ephemeral PR environment (apply + destroy)
EPHEMERAL_VAR_FILE
Var file for ephemeral PR environment
ENABLE_REPO_HYGIENE
Enable repo hygiene checks (branch protection)
FAIL_ON_REPO_HYGIENE
Fail pipeline if hygiene checks fail
Additional optional variables (health checks, dependency checks, quotas, SBOM, auto-rollback, etc.) are documented in Pipeline Stages.
Built with β€οΈ for Infrastructure as Code automation
Last Updated: January 2026
About
Reusable GitHub Actions for Terraform workflows. Includes plan, apply, validate, security scanning, cost estimation, and more. Automate your infrastructure deployments with production-ready CI/CD pipelines.