Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Commit 5ec548b

Browse files
authored
Feat/web app deployments (#4)
* Add core variables for GCP infrastructure and remove obsolete network variables * Refactor variable descriptions in variables.tf for clarity and consistency * Add core GCP infrastructure modules for Cloud SQL and VPC networking * Refactor GCP infrastructure setup: consolidate modules, add lifecycle config, and enhance variable definitions * Refactor variables in variables.tf: remove obsolete network_self_link variable and reorder authorized_networks definition for clarity * Refactor variable descriptions in variables.tf for consistency and clarity; remove obsolete network_self_link variable. * Add provider configuration and refactor Cloud SQL module: replace obsolete network_self_link with direct reference to VPC network; remove outputs.tf file. * Add Cloud Run and GCS infrastructure: create service accounts, build triggers, storage buckets, and IAM bindings; enhance variable definitions and descriptions for clarity. * Update GCS bucket names in backend configuration for dev and prod environments * Refactor init script for environment setup: improve error handling, streamline variable loading, and enhance bucket creation logic. * Fix formatting in backend.tf: add newline at end of file for consistency * Remove .env files from .gitignore to allow environment variable management * Add environment configuration files and update Terraform templates for core infrastructure - Create dev.env and prod.env for environment variable management - Enhance init.sh to validate additional variables and create environment directories - Add main.tf, provider.tf, and variables.tf templates for core module configuration - Update backend.tf for GCS state management with dynamic prefixes * Update terraform.tfvars generation to include network and database configuration variables * Add terraform.tfvars.template for environment configuration in init directory * Add lifecycle configuration for GCS bucket and update age and versioning rules * Add 'env' variable to Terraform configuration for environment specification * Add dependency on network peering routes for SQL database instance * Add initial Terraform configuration for shared services environment * Add GCS web app module and Cloud Build trigger configuration * Add GCS web app load balancer configuration and update variables * Add GCS web app module configuration and enable service account dependencies * Refactor IAM resource names for consistency and add dependencies for Cloud Build service account * Fix dependency order for service networking connection in network module * Add template.env for environment configuration and remove lifecycle-config.json * Remove shared services Terraform configuration files
1 parent 7572f80 commit 5ec548b

40 files changed

Lines changed: 815 additions & 309 deletions

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
*.env
2-
31
# Local .terraform directories
42
.terraform/
53

terraform/dev/backend.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
terraform {
22
backend "gcs" {
3-
bucket = "lf-dev-tf-state"
3+
bucket = "luca-ledger-dev-tf-state"
44
prefix = "tf-state/dev"
55
}
6-
}
6+
}

terraform/dev/lifecycle-config.json

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

terraform/dev/main.tf

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,41 @@
1-
provider "google" {
2-
project = "luca-ledger-dev"
3-
region = "us-central1"
4-
}
5-
6-
module "network" {
7-
source = "../modules/network"
8-
9-
project_id = "luca-ledger-dev"
10-
region = "us-central1"
11-
12-
network_name = "luca-ledger-dev-vpc-network"
13-
subnet_name = "luca-ledger-dev-subnet"
14-
subnet_ip = "10.1.1.0/24"
15-
}
16-
17-
module "sql" {
18-
source = "../modules/sql"
19-
20-
region = "us-central1"
21-
22-
db_instance_name = "luca-ledger-dev-sql"
23-
db_version = "POSTGRES_16"
24-
db_name = "ledger"
25-
deletion_protection = true
26-
network_self_link = module.network.network_self_link
27-
1+
module "core" {
2+
source = "../modules/core"
3+
4+
project_id = var.project_id
5+
region = var.region
6+
7+
network_name = var.network_name
8+
subnet_name = var.subnet_name
9+
subnet_ip = var.subnet_ip
10+
11+
db_version = var.db_version
12+
db_instance_name = var.db_instance_name
13+
db_name = var.db_name
14+
2815
db_admin_username = var.db_admin_username
2916
db_admin_password = var.db_admin_password
17+
3018
db_user_username = var.db_user_username
3119
db_user_password = var.db_user_password
20+
21+
deletion_protection = var.deletion_protection
3222
authorized_networks = var.authorized_networks
23+
}
24+
25+
module "web-app-gcs" {
26+
source = "../modules/web-app-gcs"
27+
28+
env = var.env
29+
project_id = var.project_id
30+
region = var.region
3331

34-
depends_on = [module.network]
32+
service_account_name_gcs = "cloud-build-sa-gcs"
33+
service_name_gcs = "luca-ledger-dev-web-app-gcs"
34+
35+
branch_pattern = ".*"
36+
bucket_name = "luca-ledger-dev-web-app"
37+
38+
ssl_domains = ["dev.lucaledger.app"]
3539
}
40+
41+
#module "web-app-cloud-run" {}

terraform/dev/provider.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_providers {
3+
google = {
4+
source = "hashicorp/google"
5+
version = ">= 4.46.0"
6+
}
7+
}
8+
required_version = ">= 1.3.0"
9+
}
10+
11+
provider "google" {
12+
project = var.project_id
13+
region = var.region
14+
}

terraform/dev/variables.tf

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,77 @@
1-
variable "db_user_username" {
2-
description = "Database user username"
1+
variable "env" {
32
type = string
3+
description = "The environment"
44
}
55

6-
variable "db_user_password" {
7-
description = "Database user password"
6+
variable "project_id" {
87
type = string
9-
sensitive = true
8+
description = "The ID of the GCP project"
9+
}
10+
11+
variable "region" {
12+
type = string
13+
description = "The region where resources will be deployed"
14+
}
15+
16+
variable "network_name" {
17+
type = string
18+
description = "The name of the VPC network"
19+
}
20+
21+
variable "subnet_name" {
22+
type = string
23+
description = "The name of the subnet within the VPC"
24+
}
25+
26+
variable "subnet_ip" {
27+
type = string
28+
description = "The IP CIDR range of the subnet (e.g., 10.0.0.0/24)"
29+
}
30+
31+
variable "db_version" {
32+
type = string
33+
description = "The Cloud SQL database version (e.g., POSTGRES_13)"
34+
}
35+
36+
variable "db_instance_name" {
37+
type = string
38+
description = "The name to assign to the Cloud SQL instance"
39+
}
40+
41+
variable "db_name" {
42+
type = string
43+
description = "The name of the initial database to create"
1044
}
1145

1246
variable "db_admin_username" {
13-
description = "Database admin user name"
1447
type = string
15-
sensitive = true
48+
description = "The admin username for the Cloud SQL instance"
1649
}
1750

1851
variable "db_admin_password" {
19-
description = "Database admin password"
2052
type = string
53+
description = "The password for the database admin user"
54+
sensitive = true
55+
}
56+
57+
variable "db_user_username" {
58+
type = string
59+
description = "The username for the application-level database user"
60+
}
61+
62+
variable "db_user_password" {
63+
type = string
64+
description = "The password for the application-level database user"
2165
sensitive = true
2266
}
2367

68+
variable "deletion_protection" {
69+
type = bool
70+
description = "Whether to enable deletion protection on the Cloud SQL instance"
71+
}
72+
2473
variable "authorized_networks" {
25-
description = "Networks to add to the white list for allowed access"
74+
description = "List of external networks authorized to connect to the database"
2675
type = list(object({
2776
name = string
2877
value = string

terraform/init/env/dev.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ENV=dev
2+
GCP_PROJECT=luca-ledger-dev
3+
TF_STATE_BUCKET=luca-ledger-dev-tf-state
4+
TF_STATE_PATH=tf-state/dev
5+
REGION=us-central1

terraform/init/env/prod.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ENV=prod
2+
GCP_PROJECT=luca-ledger-prod
3+
TF_STATE_BUCKET=luca-ledger-prod-tf-state
4+
TF_STATE_PATH=tf-state/prod
5+
REGION=us-central1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ENV=shared-services
2+
GCP_PROJECT=luca-ledger-shared-services
3+
TF_STATE_BUCKET=luca-ledger-shared-services-tf-state
4+
TF_STATE_PATH=tf-state/shared-services
5+
REGION=us-central1

terraform/init/env/template.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PROJECT_ID=
2+
BUCKET_NAME=lf-dev-tf-state
3+
BUCKET_REGION=us-central1
4+
ENABLE_VERSIONING=true

0 commit comments

Comments
 (0)