Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
797f567
added permissions for network
Tian-T000 Jul 28, 2025
1979375
added vpc
Tian-T000 Jul 28, 2025
eb71f8d
Merge branch 'main' of github.com:jjyy032659/devops-recipe-app-api
Tian-T000 Jul 28, 2025
0becf49
added network
Tian-T000 Jul 30, 2025
44a1680
added private subnets
Tian-T000 Jul 30, 2025
8d7fa91
added endpoints
Tian-T000 Aug 1, 2025
cbc0e46
update iam user for rds
Tian-T000 Aug 1, 2025
f5e9559
added rds instance
Tian-T000 Aug 2, 2025
075779a
Merge pull request #4 from jjyy032659/add-rds-instance
jjyy032659 Aug 2, 2025
fcc16b5
added rds instance
Tian-T000 Aug 2, 2025
3d723a7
Merge pull request #5 from jjyy032659/add-rds-instance
jjyy032659 Aug 2, 2025
666eebb
updated added rds instance
Tian-T000 Aug 2, 2025
bbdfe8f
Merge pull request #6 from jjyy032659/update-add-rds-instance
jjyy032659 Aug 2, 2025
3bb8af3
updated added rds instances
Tian-T000 Aug 2, 2025
999f50e
update readme
Tian-T000 Aug 2, 2025
c608457
Merge pull request #7 from jjyy032659/secondUpdated_added_rds_instance
jjyy032659 Aug 2, 2025
db5aa83
added new rds iam
Tian-T000 Aug 2, 2025
9b5c8ab
Merge pull request #8 from jjyy032659/added-iam
jjyy032659 Aug 2, 2025
547e4c4
updated iam
Tian-T000 Aug 2, 2025
94031cc
Merge pull request #9 from jjyy032659/added-iam
jjyy032659 Aug 2, 2025
96c0038
add linked rds
Tian-T000 Aug 2, 2025
b79d4ab
Merge pull request #11 from jjyy032659/test-iam
jjyy032659 Aug 2, 2025
7e4a65f
add linked rds 15.4
Tian-T000 Aug 2, 2025
1145567
Merge pull request #12 from jjyy032659/test-iam
jjyy032659 Aug 2, 2025
35c977f
postres 15.7
Tian-T000 Aug 2, 2025
561db7b
Merge pull request #13 from jjyy032659/test-iam
jjyy032659 Aug 2, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,4 @@ Or find them below:
- [Deploy a Serverless Django App on Google App Engine](https://londonapp.dev/c5)


hello 123
hello 123456
53 changes: 53 additions & 0 deletions infra/deploy/database.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
############
# Database #
############

resource "aws_db_subnet_group" "main" {
name = "${local.prefix}-main"
subnet_ids = [
aws_subnet.private_a.id,
aws_subnet.private_b.id
]

tags = {
Name = "${local.prefix}-db-subnet-group"
}
}

resource "aws_security_group" "rds" {
description = "Allow access to the RDS database instance."
name = "${local.prefix}-rds-inbound-access"
vpc_id = aws_vpc.main.id

ingress {
protocol = "tcp"
from_port = 5432
to_port = 5432
}

tags = {
Name = "${local.prefix}-db-security-group"
}
}

resource "aws_db_instance" "main" {
identifier = "${local.prefix}-db"
db_name = "recipe"
allocated_storage = 20
storage_type = "gp2"
engine = "postgres"
engine_version = "15.7"
auto_minor_version_upgrade = true
instance_class = "db.t4g.micro"
username = var.db_username
password = var.db_password
skip_final_snapshot = true
db_subnet_group_name = aws_db_subnet_group.main.name
multi_az = false
backup_retention_period = 0
vpc_security_group_ids = [aws_security_group.rds.id]

tags = {
Name = "${local.prefix}-main"
}
}
206 changes: 206 additions & 0 deletions infra/deploy/network.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
##Network infra ##

##########################
# Network infrastructure #
##########################

resource "aws_vpc" "main" {
cidr_block = "10.1.0.0/16"
enable_dns_hostnames = true
enable_dns_support = true
}

#########################################################
# Internet Gateway needed for inbound access to the ALB #
#########################################################
resource "aws_internet_gateway" "main" {
vpc_id = aws_vpc.main.id

tags = {
Name = "${local.prefix}-main"
}
}

##################################################
# Public subnets for load balancer public access #
##################################################
resource "aws_subnet" "public_a" {
vpc_id = aws_vpc.main.id
cidr_block = "10.1.1.0/24"
map_public_ip_on_launch = true
availability_zone = "${data.aws_region.current.name}a"

tags = {
Name = "${local.prefix}-public-a"
}
}

resource "aws_route_table" "public_a" {
vpc_id = aws_vpc.main.id

tags = {
Name = "${local.prefix}-public-a"
}
}

resource "aws_route_table_association" "public_a" {
subnet_id = aws_subnet.public_a.id
route_table_id = aws_route_table.public_a.id
}

resource "aws_route" "public_internet_access_a" {
route_table_id = aws_route_table.public_a.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.main.id
}

resource "aws_subnet" "public_b" {
vpc_id = aws_vpc.main.id
cidr_block = "10.1.2.0/24"
map_public_ip_on_launch = true
availability_zone = "${data.aws_region.current.name}b"

tags = {
Name = "${local.prefix}-public-b"
}
}

resource "aws_route_table" "public_b" {
vpc_id = aws_vpc.main.id

tags = {
Name = "${local.prefix}-public-b"
}
}

resource "aws_route_table_association" "public_b" {
subnet_id = aws_subnet.public_b.id
route_table_id = aws_route_table.public_b.id
}

resource "aws_route" "public_internet_access_b" {
route_table_id = aws_route_table.public_b.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.main.id
}

############################################
# Private Subnets for internal access only #
############################################
resource "aws_subnet" "private_a" {
vpc_id = aws_vpc.main.id
cidr_block = "10.1.10.0/24"
availability_zone = "${data.aws_region.current.name}a"

tags = {
Name = "${local.prefix}-private-a"
}
}

resource "aws_subnet" "private_b" {
vpc_id = aws_vpc.main.id
cidr_block = "10.1.11.0/24"
availability_zone = "${data.aws_region.current.name}b"

tags = {
Name = "${local.prefix}-private-b"
}
}


#########################################################################
## Endpoints to allow ECS to access ECR, CloudWatch and Systems Manager #
#########################################################################

resource "aws_security_group" "endpoint_access" {
description = "Access to endpoints"
name = "${local.prefix}-endpoint-access"
vpc_id = aws_vpc.main.id

ingress {
cidr_blocks = [aws_vpc.main.cidr_block]
from_port = 443
to_port = 443
protocol = "tcp"
}
}

resource "aws_vpc_endpoint" "ecr" {
vpc_id = aws_vpc.main.id
service_name = "com.amazonaws.${data.aws_region.current.name}.ecr.api"
vpc_endpoint_type = "Interface"
private_dns_enabled = true

subnet_ids = [aws_subnet.private_a.id, aws_subnet.private_b.id]

security_group_ids = [
aws_security_group.endpoint_access.id
]

tags = {
Name = "${local.prefix}-ecr-endpoint"
}
}

resource "aws_vpc_endpoint" "dkr" {
vpc_id = aws_vpc.main.id
service_name = "com.amazonaws.${data.aws_region.current.name}.ecr.dkr"
vpc_endpoint_type = "Interface"
private_dns_enabled = true

subnet_ids = [aws_subnet.private_a.id, aws_subnet.private_b.id]

security_group_ids = [
aws_security_group.endpoint_access.id
]

tags = {
Name = "${local.prefix}-dkr-endpoint"
}
}

resource "aws_vpc_endpoint" "cloudwatch_logs" {
vpc_id = aws_vpc.main.id
service_name = "com.amazonaws.${data.aws_region.current.name}.logs"
vpc_endpoint_type = "Interface"
private_dns_enabled = true

subnet_ids = [aws_subnet.private_a.id, aws_subnet.private_b.id]

security_group_ids = [
aws_security_group.endpoint_access.id
]

tags = {
Name = "${local.prefix}-cloudwatch-endpoint"
}
}

resource "aws_vpc_endpoint" "ssm" {
vpc_id = aws_vpc.main.id
service_name = "com.amazonaws.${data.aws_region.current.name}.ssmmessages"
vpc_endpoint_type = "Interface"
private_dns_enabled = true

subnet_ids = [aws_subnet.private_a.id, aws_subnet.private_b.id]

security_group_ids = [
aws_security_group.endpoint_access.id
]

tags = {
Name = "${local.prefix}-ssmmessages-endpoint"
}
}

resource "aws_vpc_endpoint" "s3" {
vpc_id = aws_vpc.main.id
service_name = "com.amazonaws.${data.aws_region.current.name}.s3"
vpc_endpoint_type = "Gateway"
route_table_ids = [
aws_vpc.main.default_route_table_id
]
tags = {
Name = "${local.prefix}-s3-endpoint"
}
}
9 changes: 9 additions & 0 deletions infra/deploy/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@ variable "project" {
variable "contact" {
description = "Contact email for tagging resources"
default = "mark@example.com"
}

variable "db_username" {
description = "Username for the recipe app api database"
default = "recipeapp"
}

variable "db_password" {
description = "Password for the Terraform database"
}
3 changes: 2 additions & 1 deletion infra/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ services:
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
- AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}
- AWS_DEFAULT_REGION=ap-southeast-2
- TF_WORKSPACE=${TF_WORKSPACE}
- TF_WORKSPACE=${TF_WORKSPACE}
- TF_VAR_db_password=${TF_VAR_db_password}
Loading