File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ name : ' Terraform CI/CD'
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ pull_request :
8+
9+ jobs :
10+ terraform :
11+ name : ' Terraform'
12+ runs-on : ubuntu-latest
13+ env :
14+ TF_VAR_project_id : ${{ secrets.GCP_PROJECT_ID }} # Make sure to set this secret in your repository
15+
16+ steps :
17+ - name : ' Checkout'
18+ uses : actions/checkout@v4
19+
20+ - name : ' Authenticate to Google Cloud'
21+ uses : ' google-github-actions/auth@v2'
22+ with :
23+ credentials_json : ' ${{ secrets.GCP_SA_KEY }}' # Make sure to set this secret in your repository
24+
25+ - name : ' Set up Terraform'
26+ uses : hashicorp/setup-terraform@v3
27+ with :
28+ terraform_version : latest # Or specify a version e.g., 1.0.0
29+
30+ - name : ' Terraform Init'
31+ id : init
32+ run : terraform init
33+ working-directory : ./terraform # Assuming your Terraform files are in a 'terraform' subdirectory
34+
35+ - name : ' Terraform Validate'
36+ id : validate
37+ run : terraform validate -no-color
38+ working-directory : ./terraform
39+
40+ - name : ' Terraform Plan'
41+ id : plan
42+ run : terraform plan -no-color -input=false -out=tfplan
43+ working-directory : ./terraform
44+ # Only run on pull requests or direct pushes to main (not on merges)
45+ if : github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
46+
47+ - name : ' Terraform Apply'
48+ id : apply
49+ run : terraform apply -auto-approve -input=false tfplan
50+ working-directory : ./terraform
51+ # Only run on pushes to the main branch (e.g., after a PR is merged)
52+ if : github.ref == 'refs/heads/main' && github.event_name == 'push'
Original file line number Diff line number Diff line change 1+ #
You can’t perform that action at this time.
0 commit comments