Skip to content
Open
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,9 @@ backend/filepond-temp-uploads
backend/media
backend/*.sqlite3*
frontend/assets/fonts

*.auto.tfvars
.terraform/
.terraformrc
*.tfstate
terraform.tfstate.backup
2 changes: 1 addition & 1 deletion docker/Dockerfile.nginx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG NODE_VERSION="18.20-bullseye-slim"
ARG NODE_VERSION="20.19-bullseye-slim"
FROM node:${NODE_VERSION} AS frontend-builder

COPY frontend/ /app/
Expand Down
2 changes: 1 addition & 1 deletion docker/nginx/nginx.conf.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
worker_processes ${WORKER_PROCESSES};
worker_processes auto;

error_log /var/log/nginx/error.log warn;

Expand Down
43 changes: 43 additions & 0 deletions terraform/.terraform.lock.hcl

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

43 changes: 43 additions & 0 deletions terraform/dev/.terraform.lock.hcl

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

87 changes: 87 additions & 0 deletions terraform/dev/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
module "doccano_ecs" {
source = "../modules/ecs"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you defining a new module here instead of using https://github.com/chicagopcdc/terraform_modules/tree/main/aws/ecs?

Is it a use case that is hard to generalize and parametrize?
If so that is good, otherwise we should try to move the module to the terraform module repo and import it here so we can reuse it for other projects.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, I will update this to use module with reference to terraform_modules repo, initially I thought local reference was more appropriate

app_name = var.app_name
subnet_ids = var.private_subnet_ids
lb_security_group = [module.doccano_alb.alb_security_group]
load_balancer = {
container_port = 8080
}
vpc_id = var.vpc_id
target_group_arn = module.doccano_alb.alb_target_group_arn
container_name = "nginx"
# container_count = 2
efs_volume = module.doccano_efs.efs_id
efs_access_point_static_files = module.doccano_efs.access_point_ids["staticfiles"]
efs_access_point_id_media = module.doccano_efs.access_point_ids["media"]
efs_access_point_id_tmp = module.doccano_efs.access_point_ids["tmp"]
database_url = aws_ssm_parameter.DATABASE_URL.arn
}

module "doccano_efs" {
source = "git::ssh://git@github.com/chicagopcdc/terraform_modules.git//aws/efs?ref=0.5.0"
vpc_id = var.vpc_id
efs_name = var.app_name
subnet_ids = var.private_subnet_ids
security_groups = [module.doccano_ecs.ecs_tasks_sg]
access_points = [
{
name = "media"
posix_user = { uid = 1000, gid = 1000 }
root_directory = {
path = "/backend/media"
creation_info = {
owner_uid = "1000"
owner_gid = "1000"
permissions = "755"
}
}
},
{
name = "staticfiles"
posix_user = { uid = 1000, gid = 1000 }
root_directory = {
path = "/backend/staticfiles"
creation_info = {
owner_uid = "1000"
owner_gid = "1000"
permissions = "755"
}
}
},
{
name = "tmp"
posix_user = { uid = 1000, gid = 1000 }
root_directory = {
path = "/backend/filepond-temp-uploads"
creation_info = {
owner_uid = "1000"
owner_gid = "1000"
permissions = "755"
}
}
}
]
}

module "doccano_alb" {
source = "git::ssh://git@github.com/chicagopcdc/terraform_modules.git//aws/alb?ref=0.5.0"
environment = var.environment
app_name = "doccano"
vpc_id = var.vpc_id
subnet_ids = var.private_subnet_ids
acm_cert_arn = "arn:aws:acm:us-east-1:471835990085:certificate/c1cebe37-738d-4766-a635-bc23d3e8caa7" #

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, this should be a variable, we shouldn't hardcode it.

}

module "rds" {
source = "git::ssh://git@github.com/chicagopcdc/terraform_modules.git//aws/rds?ref=0.5.0"
rds_security_groups = module.doccano_ecs.ecs_tasks_sg
vpc_id = var.vpc_id
subnet_ids = var.private_subnet_ids
db_name = "doccano"
}

resource "aws_ssm_parameter" "DATABASE_URL" {
name = "/${var.environment}/${var.app_name}/DATABASE_URL"
type = "SecureString"
value = "postgres://doccano:${module.rds.rds_random_password}@${module.rds.rds_enpoint}/doccano?sslmode=disable"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is rds_enpoint just a typo here or is it carried from the imported module output?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should update sslmode=require instead of disable. The new version of RDS enforce the SSL.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, it was just taken from current values at the time

}
19 changes: 19 additions & 0 deletions terraform/dev/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
provider "aws" {
region = var.aws_region
default_tags {
tags = {
Environment = var.environment
Name = var.app_name
}
}
}

# terraform {
# backend "s3" {
# bucket = "pcdc-doccano-dev-tfstate-bucket"
# key = "terraform.tfstate"
# region = var.aws_region
# dynamodb_table = "pcdc-doccano-dynomodb-table-terraform-lock"
# encrypt = true
# }
# }
27 changes: 27 additions & 0 deletions terraform/dev/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
variable "aws_region" {
default = "us-east-1"
}

variable "environment" {
default = "dev"
}

variable "app_name" {
default = "doccano"
}

variable "private_subnet_ids" {
default = ["subnet-02daaea0d231975df", "subnet-0c7f4570d0c82bdc3"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should be in the tfvars, we shouldn't default to them.

}

variable "vpc_id" {
default = "vpc-0e20603ab3c8dd65e" #doccano dev vpc

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be in the tfvars, we shouldn't default to it.

}

variable "efs_sg_id" {
default = ""
}

# variable "alb_sg_id" {
# default = ""
# }
3 changes: 3 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module "dev" {
source = "./dev"
}
24 changes: 24 additions & 0 deletions terraform/modules/ecs/cloudwatch.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
resource "aws_cloudwatch_log_group" "doccano" {
name = "/ecs/doccano-logs"
retention_in_days = 7
}

resource "aws_cloudwatch_log_group" "flower" {
name = "/ecs/flower-logs"
retention_in_days = 7
}

resource "aws_cloudwatch_log_group" "celery" {
name = "/ecs/celery-logs"
retention_in_days = 7
}

resource "aws_cloudwatch_log_group" "nginx" {
name = "/ecs/nginx-logs"
retention_in_days = 7
}

resource "aws_cloudwatch_log_group" "rabbitmq" {
name = "/ecs/rabbitmq-logs"
retention_in_days = 7
}
3 changes: 3 additions & 0 deletions terraform/modules/ecs/cluster.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "aws_ecs_cluster" "cluster" {
name = "${var.environment}-cluster"
}
Loading
Loading