Skip to content

Commit ce0234c

Browse files
authored
Updated workflow files (#11)
* Updated all files for proper version constraints * Added new NAt IP * Updated subnet module for adding log_config and private_ip_google_access * Added service account and vm modules with a test vm instance * Generated documents for each module using terraform-docs * Generated documents for dev environment using terraform-docs * Added more modules * Updated workflow files
1 parent 6ae88ee commit ce0234c

File tree

4 files changed

+105
-55
lines changed

4 files changed

+105
-55
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Terraform Apply
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
apply:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v3
14+
15+
- name: Set Environment Folder
16+
id: env
17+
run: |
18+
if git diff-tree --no-commit-id --name-only -r ${{ github.sha }} | grep '^environments/dev/'; then
19+
echo "env_folder=environments/dev" >> $GITHUB_OUTPUT
20+
elif git diff-tree --no-commit-id --name-only -r ${{ github.sha }} | grep '^environments/prod/'; then
21+
echo "env_folder=environments/prod" >> $GITHUB_OUTPUT
22+
else
23+
echo "env_folder=" >> $GITHUB_OUTPUT
24+
fi
25+
26+
- name: Exit if No Matching Env
27+
if: steps.env.outputs.env_folder == ''
28+
run: echo "No changes to dev or prod environments. Skipping apply."
29+
30+
- name: Decode GCP SA
31+
if: steps.env.outputs.env_folder != ''
32+
run: echo "${{ secrets.GCP_SA_KEY_BASE64 }}" | base64 -d > gcp-creds.json
33+
34+
- name: Set up Terraform
35+
if: steps.env.outputs.env_folder != ''
36+
uses: hashicorp/setup-terraform@v2
37+
with:
38+
terraform_version: 1.11.4
39+
40+
- name: Terraform Init & Apply
41+
if: steps.env.outputs.env_folder != ''
42+
working-directory: ${{ steps.env.outputs.env_folder }}
43+
run: |
44+
terraform init
45+
terraform apply -auto-approve

.github/workflows/terraform-plan-dev.yml

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,9 @@ on:
55
branches: [dev]
66
paths:
77
- "environments/dev/**"
8-
pull_request:
9-
branches: [dev]
10-
paths:
11-
- "environments/dev/**"
12-
13-
env:
14-
GOOGLE_APPLICATION_CREDENTIALS: ${{ github.workspace }}/gcp-creds.json
158

169
jobs:
17-
plan-dev:
18-
runs-on: ubuntu-latest
19-
20-
steps:
21-
- name: Checkout code
22-
uses: actions/checkout@v3
23-
24-
- name: Decode GCP Service Account Key
25-
run: echo "${{ secrets.GCP_SA_KEY_BASE64 }}" | base64 -d > "$GOOGLE_APPLICATION_CREDENTIALS"
26-
27-
- name: Set up Terraform
28-
uses: hashicorp/setup-terraform@v2
29-
with:
30-
terraform_version: 1.11.4
31-
32-
- name: Terraform Init
33-
working-directory: environments/dev
34-
run: terraform init
35-
36-
- name: Terraform FMT Check
37-
working-directory: environments/dev
38-
run: terraform fmt -check
39-
40-
- name: Terraform Validate
41-
working-directory: environments/dev
42-
run: terraform validate
43-
44-
- name: Setup TFLint
45-
uses: terraform-linters/setup-tflint@v3
46-
with:
47-
tflint_version: latest
48-
49-
- name: Run TFLint
50-
working-directory: environments/dev
51-
run: |
52-
tflint --init
53-
tflint --recursive
54-
55-
- name: Run Checkov (Security Scan)
56-
run: |
57-
pip install checkov
58-
checkov -d environments/dev --soft-fail -o github_failed_only
59-
env:
60-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61-
62-
- name: Terraform Plan
63-
working-directory: environments/dev
64-
run: terraform plan
10+
call-plan:
11+
uses: ./.github/workflows/terraform-plan.yml
12+
with:
13+
environment: dev
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Terraform Plan (Prod)
2+
3+
on:
4+
push:
5+
branches: [prod]
6+
paths:
7+
- "environments/prod/**"
8+
9+
jobs:
10+
call-plan:
11+
uses: ./.github/workflows/terraform-plan.yml
12+
with:
13+
environment: prod
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Terraform Plan (Reusable)
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
environment:
7+
required: true
8+
type: string
9+
10+
jobs:
11+
plan:
12+
runs-on: ubuntu-latest
13+
14+
env:
15+
GOOGLE_APPLICATION_CREDENTIALS: ${{ github.workspace }}/gcp-creds.json
16+
17+
steps:
18+
- name: Checkout repo
19+
uses: actions/checkout@v3
20+
21+
- name: Decode GCP Service Account
22+
run: echo "${{ secrets.GCP_SA_KEY_BASE64 }}" | base64 -d > "$GOOGLE_APPLICATION_CREDENTIALS"
23+
24+
- name: Setup Terraform
25+
uses: hashicorp/setup-terraform@v2
26+
with:
27+
terraform_version: 1.11.4
28+
29+
- name: Terraform Init
30+
working-directory: environments/${{ inputs.environment }}
31+
run: terraform init
32+
33+
- name: Terraform Format
34+
working-directory: environments/${{ inputs.environment }}
35+
run: terraform fmt -check
36+
37+
- name: Terraform Validate
38+
working-directory: environments/${{ inputs.environment }}
39+
run: terraform validate
40+
41+
- name: Terraform Plan
42+
working-directory: environments/${{ inputs.environment }}
43+
run: terraform plan

0 commit comments

Comments
 (0)