GitHub Actions
Automate your Terraform deployments using GitHub Actions for secure, repeatable, and cloud-agnostic workflows. This guide covers best practices for Azure, but the pattern applies to AWS and GCP as well.
Prerequisites
Remote Terraform state (e.g., Azure Storage Account, AWS S3, or GCP Cloud Storage)
Service Principal (Azure) or equivalent credentials for AWS/GCP
Store credentials as GitHub Secrets (never commit credentials to code)
Step-by-Step: GitHub Actions Workflow for Terraform (Azure Example)
Add the following workflow to
.github/workflows/terraform.yml
in your repo:
Add GitHub Secrets under your repository settings:
AZURE_AD_CLIENT_ID
→clientId
from your Service PrincipalAZURE_AD_CLIENT_SECRET
→clientSecret
AZURE_AD_TENANT_ID
→tenantId
AZURE_SUBSCRIPTION_ID
→subscriptionId
(Optional)
AZURE_CREDENTIALS
→ full JSON output for some modules
Best Practices
Use remote state for collaboration and disaster recovery
Store credentials only in GitHub Secrets or a secure vault
Use separate Service Principals for dev, staging, and prod
Rotate credentials regularly
Use the latest stable GitHub Actions and Terraform versions
References
Tip: For AWS and GCP, use the respective provider environment variables and credentials in the same workflow pattern.
Add to SUMMARY.md
Last updated