Skip to content

Commit 7e35253

Browse files
committed
Add Terraform CI/CD workflow and initial Terraform configuration files
1 parent c66e477 commit 7e35253

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

.github/workflows/terraform.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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'

terraform/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#

terraform/permissions/permissions.tf

Whitespace-only changes.

0 commit comments

Comments
 (0)