Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0975e0a
Install zappa and initial example configuration
rudransh-shrivastava Oct 16, 2025
aa4eea0
add temporary IaC code for testing
rudransh-shrivastava Oct 17, 2025
18b8adb
Update code
rudransh-shrivastava Oct 17, 2025
6311813
Merge branch 'main' into feature/zappa-migration
rudransh-shrivastava Oct 17, 2025
481b928
Remove IAM and let Zappa manage it
rudransh-shrivastava Oct 18, 2025
ee1edb6
add README
rudransh-shrivastava Oct 18, 2025
90e24e1
add RDS proxy, pre-commit hooks, clean-up code
rudransh-shrivastava Oct 19, 2025
e618808
feat: add ecs tasks
rudransh-shrivastava Oct 23, 2025
6220c24
refactor/clean cache module
rudransh-shrivastava Oct 23, 2025
9495dfd
refactor/clean database module
rudransh-shrivastava Oct 23, 2025
df72c9a
refactor/clean ecs module
rudransh-shrivastava Oct 23, 2025
619400e
refactor/clean networking module
rudransh-shrivastava Oct 23, 2025
b8b49fa
address Sonar Qube bot suggestions
rudransh-shrivastava Oct 23, 2025
8c3569d
keep some Sonar Qube bot suggestions but add #NOSONAR
rudransh-shrivastava Oct 23, 2025
91b12e7
add terraform dictionary
rudransh-shrivastava Oct 23, 2025
92469ac
refactor/clean security module
rudransh-shrivastava Oct 23, 2025
1a66c4f
fix pre-commit hooks and add terraform_validate
rudransh-shrivastava Oct 23, 2025
6994e33
add SHA hash and remove terraform_validate
rudransh-shrivastava Oct 23, 2025
a41221f
refactor/clean storage module
rudransh-shrivastava Oct 23, 2025
1165166
Update docs
rudransh-shrivastava Oct 23, 2025
cc80292
add S3 support for load-data task
rudransh-shrivastava Oct 23, 2025
c694c57
Update README and necessary examples
rudransh-shrivastava Oct 23, 2025
753e234
coderabbit suggestions
rudransh-shrivastava Oct 23, 2025
16445dc
Update code: install awscli before invoking aws in task
rudransh-shrivastava Oct 23, 2025
536e615
update README
rudransh-shrivastava Oct 23, 2025
206e60e
NOSONAR
rudransh-shrivastava Oct 23, 2025
0a8b4ea
Merge branch 'main' into feature/zappa-migration
rudransh-shrivastava Oct 23, 2025
748ed52
update README
rudransh-shrivastava Oct 23, 2025
f71861c
fix spell check
rudransh-shrivastava Oct 23, 2025
e785a42
Update README
rudransh-shrivastava Oct 24, 2025
bc3737e
fix: typo
rudransh-shrivastava Oct 24, 2025
e51d34b
remove immutable tagged images
rudransh-shrivastava Oct 24, 2025
d419073
fix: load-data task fail due to no permissions
rudransh-shrivastava Oct 24, 2025
a347969
fix spell check: add PYTHONPATH
rudransh-shrivastava Oct 24, 2025
88af956
add AWS CLI
rudransh-shrivastava Oct 24, 2025
5be1083
add set -e
rudransh-shrivastava Oct 24, 2025
9650e5e
Update code
arkid15r Oct 26, 2025
d4f7ddd
Merge branch 'feature/nest-zappa-migration' into pr/rudransh-shrivast…
arkid15r Oct 26, 2025
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
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@ __pycache__
.python_history
.python-version
.ruff_cache
**/.terraform/
*.tfstate
*.tfstate.*
.venv/
.vscode
*.code-workspace
*.key
*.log
*.pdf
*.pem
backend/*nest-backend-dev*.zip
backend/*nest-backend-dev*.tar.gz
backend/*nest-backend-staging*.zip
backend/*nest-backend-staging*.tar.gz
backend/data/backup*
backend/staticfiles
backend/zappa_settings.json
frontend/blob-report/
frontend/coverage
frontend/dist
Expand All @@ -36,6 +44,7 @@ frontend/pnpm-debug.log*
frontend/test-results/
frontend/yarn-debug.log*
frontend/yarn-error.log*
infrastructure/terraform.tfvars
logs
node_modules/
TODO
Expand Down
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ repos:
- --strict
exclude: (.github|pnpm-lock.yaml)

- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.92.0
hooks:
- id: terraform_fmt
files: ^infrastructure/.*\.tf$
- id: terraform_tflint
files: ^infrastructure/.*\.tf$

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.0
hooks:
Expand Down
1,224 changes: 738 additions & 486 deletions backend/poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ strawberry-graphql = { extras = [ "django" ], version = "^0.283.2" }
strawberry-graphql-django = "^0.66.0"
thefuzz = "^0.22.1"
pyparsing = "^3.2.3"
zappa = "^0.60.2"

[tool.poetry.group.dev.dependencies]
djlint = "^1.36.4"
Expand Down
39 changes: 39 additions & 0 deletions backend/zappa_settings.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"staging": {
"app_function": "wsgi.application",
"django_settings": "settings.staging",
"environment_variables": {
"DJANGO_ALGOLIA_APPLICATION_ID": "${DJANGO_ALGOLIA_APPLICATION_ID}",
"DJANGO_ALGOLIA_WRITE_API_KEY": "${DJANGO_ALGOLIA_WRITE_API_KEY}",
"DJANGO_ALLOWED_HOSTS": "${DJANGO_ALLOWED_HOSTS}",
"DJANGO_AWS_ACCESS_KEY_ID": "${DJANGO_AWS_ACCESS_KEY_ID}",
"DJANGO_AWS_SECRET_ACCESS_KEY": "${DJANGO_AWS_SECRET_ACCESS_KEY}",
"DJANGO_CONFIGURATION": "Staging",
"DJANGO_DB_HOST": "${DJANGO_DB_HOST}",
"DJANGO_DB_NAME": "${DJANGO_DB_NAME}",
"DJANGO_DB_USER": "${DJANGO_DB_USER}",
"DJANGO_DB_PORT": "${DJANGO_DB_PORT}",
"DJANGO_DB_PASSWORD": "${DJANGO_DB_PASSWORD}",
"DJANGO_OPEN_AI_SECRET_KEY": "${DJANGO_OPEN_AI_SECRET_KEY}",
"DJANGO_REDIS_HOST": "${DJANGO_REDIS_HOST}",
"DJANGO_REDIS_PASSWORD": "${DJANGO_REDIS_PASSWORD}",
"DJANGO_SECRET_KEY": "${DJANGO_SECRET_KEY}",
"DJANGO_SENTRY_DSN": "${DJANGO_SENTRY_DSN}",
"DJANGO_SLACK_BOT_TOKEN": "${DJANGO_SLACK_BOT_TOKEN}",
"DJANGO_SLACK_SIGNING_SECRET": "${DJANGO_SLACK_SIGNING_SECRET}"
},
"manage_roles": true,
"project_name": "nest-backend",
"runtime": "python3.13",
"s3_bucket": "${ZAPPA_S3_BUCKET}",
"slim_handler": true,
"vpc_config": {
"SecurityGroupIds": ["${AWS_VPC_SECURITY_GROUP}"],
"SubnetIds": [
"${AWS_VPC_SUBNET_A}",
"${AWS_VPC_SUBNET_B}",
"${AWS_VPC_SUBNET_C}"
]
}
}
}
43 changes: 43 additions & 0 deletions infrastructure/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 105 additions & 0 deletions infrastructure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Infrastructure

This document provides instructions on how to manage the infrastructure for this project using Terraform and Zappa.

## Terraform

### Prerequisites

- Terraform
- An AWS account with credentials configured locally.

### Usage

1. **Initialize Terraform:**

```bash
terraform init
```

2. **Plan the changes:**

```bash
terraform plan
```

3. **Apply the changes:**

```bash
terraform apply
```

### Variables

You can override the default values by creating a `terraform.tfvars` file in the `infrastructure/` directory.

# TODO: Provide an example terraform.tfvars with important vars


### Outputs

Get the output values using the `terraform output` command. These outputs will be used for Zappa configuration.


```bash
terraform output
```

```bash
terraform output -raw db_password redis_auth_token
```

## Zappa Deployment

The Django backend deployment is managed by Zappa, this also includes the API Gateway, IAM roles, and Lambda Function provision.

### Install poetry dependencies

1. **Install dependencies using Poetry:**

```bash
poetry install
```

2. **Activate the virtual environment:**

```bash
eval $(poetry env activate)
```

3. **Create a `zappa_settings.json` file:**

```bash
cp zappa_settings.example.json zappa_settings.json
```

Replace all variables in the copied `zappa_settings.json` with appropriate secrets.
# TODO: explain this step

4. **Deploy staging:**

```bash
zappa deploy staging
```

Once deployed, Zappa will provide you with a URL. You can use this URL to test the API.

### Updating
After making necessary changes, you may run the following command to update the deployment.
```bash
zappa update staging
```

### Cleaning Up

To delete the deployment, you can use the following command:

```bash
zappa undeploy local
```

Then run this command to destroy the terraform infrastructure:

```bash
terraform destroy
```
117 changes: 117 additions & 0 deletions infrastructure/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
terraform {
required_version = ">= 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 6.0"
}
random = {
source = "hashicorp/random"
version = "~> 3.0"
}
}
}

locals {
common_tags = {
Environment = var.environment
ManagedBy = "Terraform"
Project = var.project_name
}
django_environment_variables = {
DJANGO_ALGOLIA_APPLICATION_ID = var.django_algolia_application_id
DJANGO_ALGOLIA_WRITE_API_KEY = var.django_algolia_write_api_key
DJANGO_ALLOWED_HOSTS = var.django_allowed_hosts
DJANGO_AWS_ACCESS_KEY_ID = var.django_aws_access_key_id
DJANGO_AWS_SECRET_ACCESS_KEY = var.django_aws_secret_access_key
DJANGO_CONFIGURATION = var.django_configuration
DJANGO_DB_HOST = var.django_db_host
DJANGO_DB_NAME = var.django_db_name
DJANGO_DB_USER = var.django_db_user
DJANGO_DB_PORT = var.django_db_port
DJANGO_DB_PASSWORD = var.django_db_password
DJANGO_OPEN_AI_SECRET_KEY = var.django_open_ai_secret_key
DJANGO_REDIS_HOST = var.django_redis_host
DJANGO_REDIS_PASSWORD = var.django_redis_password
DJANGO_SECRET_KEY = var.django_secret_key
DJANGO_SENTRY_DSN = var.django_sentry_dsn
DJANGO_SLACK_BOT_TOKEN = var.django_slack_bot_token
DJANGO_SLACK_SIGNING_SECRET = var.django_slack_signing_secret
}
}

module "networking" {
source = "./modules/networking"

vpc_cidr = var.vpc_cidr
public_subnet_cidrs = var.public_subnet_cidrs
private_subnet_cidrs = var.private_subnet_cidrs
availability_zones = var.availability_zones
project_name = var.project_name
environment = var.environment
}

module "security" {
source = "./modules/security"

vpc_id = module.networking.vpc_id
db_port = var.db_port
redis_port = var.redis_port
project_name = var.project_name
environment = var.environment
}

module "storage" {
source = "./modules/storage"

zappa_s3_bucket = var.zappa_s3_bucket
project_name = var.project_name
environment = var.environment
}

module "database" {
source = "./modules/database"

common_tags = local.common_tags
db_allocated_storage = var.db_allocated_storage
db_backup_retention_period = var.db_backup_retention_period
db_engine_version = var.db_engine_version
db_instance_class = var.db_instance_class
db_name = var.db_name
db_password = var.db_password
db_storage_type = var.db_storage_type
db_subnet_ids = module.networking.private_subnet_ids
db_username = var.db_username
environment = var.environment
project_name = var.project_name
proxy_security_group_ids = [module.security.rds_proxy_sg_id]
security_group_ids = [module.security.rds_sg_id]
}

module "cache" {
source = "./modules/cache"

common_tags = local.common_tags
environment = var.environment
project_name = var.project_name
redis_auth_token = var.redis_auth_token
redis_engine_version = var.redis_engine_version
redis_node_type = var.redis_node_type
redis_num_cache_nodes = var.redis_num_cache_nodes
redis_port = var.redis_port
security_group_ids = [module.security.redis_sg_id]
subnet_ids = module.networking.private_subnet_ids
}

module "ecs" {
source = "./modules/ecs"

aws_region = var.aws_region
common_tags = local.common_tags
django_environment_variables = local.django_environment_variables
environment = var.environment
lambda_sg_id = module.security.lambda_sg_id
private_subnet_ids = module.networking.private_subnet_ids
project_name = var.project_name
}
Loading