Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ jobs:
deploy:
runs-on: ubuntu-latest
needs: [test]
defaults:
run:
working-directory: ${{ github.ref == 'refs/heads/main' && './terraform/prod' || './terraform/dev' }}

steps:
- uses: actions/checkout@v6
- name: Google Cloud Auth
Expand All @@ -32,19 +30,15 @@ jobs:

- uses: hashicorp/setup-terraform@v4

- name: Terraform fmt
id: fmt
run: terraform fmt -check

- name: Terraform Init
id: init
run: terraform init

- name: Terraform Validate
id: validate
run: terraform validate -no-color

- name: Terraform Apply
id: apply
run: |
terraform apply -auto-approve
if [ "${GITHUB_REF}" = "refs/heads/main" ]; then
ENV=prod
elif [ "${GITHUB_REF}" = "refs/heads/development" ]; then
ENV=dev
else
echo "Unsupported branch for deployment: ${GITHUB_REF}"
exit 1
fi
make tf_apply ENV="$ENV"
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.PHONY: *
ENV ?= dev

tf_plan:
cd terraform/ && terraform init -reconfigure -backend-config=backend-$(ENV).hcl -upgrade && terraform fmt -check && terraform validate && terraform plan --var="environment=$(ENV)"

tf_apply:
cd terraform/ && terraform init -reconfigure -backend-config=backend-$(ENV).hcl && terraform apply -auto-approve --var="environment=$(ENV)"
2 changes: 1 addition & 1 deletion src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ COPY --chown=node:node . .

ENV PORT=8080

CMD ["npx", "functions-framework", "--target=app"]
CMD ["npx", "functions-framework", "--target=app"]
2 changes: 2 additions & 0 deletions terraform/backend-dev.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bucket = "tfstate-httparchive"
prefix = "tech-report-apis/dev"
2 changes: 2 additions & 0 deletions terraform/backend-prod.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bucket = "tfstate-httparchive"
prefix = "tech-report-apis/prod"
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 0 additions & 36 deletions terraform/dev/main.tf

This file was deleted.

19 changes: 0 additions & 19 deletions terraform/dev/variables.tf

This file was deleted.

32 changes: 20 additions & 12 deletions terraform/prod/main.tf → terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
terraform {
backend "gcs" {
bucket = "tfstate-httparchive"
prefix = "tech-report-apis/prod"
}
required_version = ">=1.11.0"

backend "gcs" {}

required_providers {
docker = {
source = "kreuzwerker/docker"
version = "3.6.2"
version = ">=3.6.2"
}
google = {
source = "hashicorp/google"
source = "hashicorp/google"
version = ">=7.13.0"
}
}
}
Expand All @@ -20,21 +21,23 @@ provider "google" {
}

module "endpoints" {
source = "./../modules/run-service"
source = "./run-service"
project = var.project
environment = var.environment
source_directory = "../../src"
source_directory = "../src"
service_name = "report-api"
region = var.region
min_instances = 1
min_instances = var.environment == "prod" ? 1 : 0
environment_variables = {
"PROJECT" = var.project
"DATABASE" = var.project_database
"DATABASE" = "${var.project_database}prod" // TODO: Update this to use ${var.environment}
}
}

module "cdn_glb" {
source = "./../modules/cdn-glb"
count = var.environment == "prod" ? 1 : 0

source = "./cdn-glb"

project = var.project
region = var.region
Expand All @@ -45,9 +48,14 @@ module "cdn_glb" {
load_balancer_name = "httparchive-load-balancer"
name_prefix = var.name_prefix

neg_name = "report-api-prod"
neg_name = "report-api-${var.environment}"
backend_service_name = "report-api"
ssl_cert_name = var.ssl_cert_name
https_proxy_name = "httparchive-load-balancer-target-proxy-2"
https_forwarding_rule_name = "httparchive-load-balancer-forwarding-rule-2"
}

moved {
from = module.cdn_glb
to = module.cdn_glb[0]
}
File renamed without changes.
3 changes: 1 addition & 2 deletions terraform/prod/variables.tf → terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ variable "region" {
variable "environment" {
description = "The environment name"
type = string
default = "prod"
}
variable "project_database" {
type = string
description = "The database name"
default = "tech-report-api-prod"
default = "tech-report-api-"
}

variable "name_prefix" {
Expand Down