Skip to content

Commit 16d750a

Browse files
committed
consolidate deployment by introducing backend configs and a Makefile
1 parent 063486e commit 16d750a

File tree

15 files changed

+43
-136
lines changed

15 files changed

+43
-136
lines changed

.github/workflows/deployment.yaml

Lines changed: 12 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ jobs:
1919
npm ci
2020
npm run test
2121
22-
deploy_development:
23-
if: github.ref == 'refs/heads/development'
22+
deploy:
23+
if: github.ref == 'refs/heads/development' || github.ref == 'refs/heads/main'
2424
runs-on: ubuntu-latest
2525
needs: [test]
2626
defaults:
2727
run:
28-
working-directory: ./terraform/dev
28+
working-directory: ./terraform
2929
steps:
3030
- uses: actions/checkout@v6
3131
- name: Google Cloud Auth
@@ -36,68 +36,17 @@ jobs:
3636

3737
- uses: hashicorp/setup-terraform@v3
3838

39-
- name: Terraform fmt
40-
id: fmt
41-
run: terraform fmt -check
42-
continue-on-error: true
43-
44-
- name: Terraform Init
45-
id: init
46-
run: terraform init
47-
48-
- name: Terraform Validate
49-
id: validate
50-
run: terraform validate -no-color
51-
52-
- name: Terraform Plan
53-
id: plan
39+
- name: Set environment variable depending on the branch name
5440
run: |
55-
terraform plan -no-color
56-
continue-on-error: true
57-
58-
- name: Terraform Plan status
59-
if: steps.plan.outcome == 'failure'
60-
run: exit 1
61-
62-
- name: Terraform Apply
63-
id: apply
64-
run: |
65-
terraform apply -auto-approve
66-
67-
deploy_production:
68-
if: github.ref == 'refs/heads/main'
69-
runs-on: ubuntu-latest
70-
needs: [test]
71-
defaults:
72-
run:
73-
working-directory: ./terraform/prod
74-
steps:
75-
- uses: actions/checkout@v6
76-
- name: Google Cloud Auth
77-
uses: 'google-github-actions/auth@v3'
78-
with:
79-
project_id: 'httparchive'
80-
credentials_json: ${{ env.PIPELINE_SA_KEY }}
41+
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
42+
echo "ENV=prod" >> $GITHUB_ENV
43+
elif [[ "${{ github.ref }}" == "refs/heads/development" ]]; then
44+
echo "ENV=dev" >> $GITHUB_ENV
45+
fi
8146
82-
- uses: hashicorp/setup-terraform@v3
83-
84-
- name: Terraform fmt
85-
id: fmt
86-
run: terraform fmt -check
87-
continue-on-error: true
88-
89-
- name: Terraform Init
90-
id: init
91-
run: terraform init
92-
93-
- name: Terraform Validate
94-
id: validate
95-
run: terraform validate -no-color
96-
97-
- name: Terraform Plan
47+
- name: Terraform Validate & Plan
9848
id: plan
99-
run: |
100-
terraform plan -no-color
49+
run: make tf_plan ENV=${{ env.ENV }}
10150
continue-on-error: true
10251

10352
- name: Terraform Plan status
@@ -106,5 +55,4 @@ jobs:
10655

10756
- name: Terraform Apply
10857
id: apply
109-
run: |
110-
terraform apply -auto-approve
58+
run: make tf_apply ENV=${{ env.ENV }}

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.PHONY: *
2+
ENV ?= dev
3+
4+
tf_plan:
5+
cd terraform/ && terraform init -reconfigure -backend-config=backend-$(ENV).hcl -upgrade && terraform fmt -check && terraform validate && terraform plan --var="environment=$(ENV)"
6+
7+
tf_apply:
8+
cd terraform/ && terraform init -reconfigure -backend-config=backend-$(ENV).hcl && terraform apply -auto-approve --var="environment=$(ENV)"

terraform/backend-dev.hcl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bucket = "tfstate-httparchive"
2+
prefix = "tech-report-apis/dev"

terraform/backend-prod.hcl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bucket = "tfstate-httparchive"
2+
prefix = "tech-report-apis/prod"

terraform/dev/main.tf

Lines changed: 0 additions & 36 deletions
This file was deleted.

terraform/dev/variables.tf

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)