Skip to content

Commit 953b9c7

Browse files
bruviobruvio-gel
andauthored
Feature/simplify (#8)
* fix: add sg rule to connect db version variable * fix: remove bastion ec2 instance and templates * feat: can limit traffic to ip is variable is set * fix: disable nat * fix: add alb output * fix: enable nat * revert: disable nat * fix: s3 default encrytion * fix: s3 default encrytion * fix: s3 default encrytion * fix: enable nat * fix: remove encryption * fix: s3 default encrytion --------- Co-authored-by: bruvio <[email protected]>
1 parent 15008b7 commit 953b9c7

17 files changed

+70
-622
lines changed

bastion.tf

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

database.tf

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,42 @@ resource "aws_db_subnet_group" "main" {
1010

1111
resource "aws_security_group" "rds" {
1212
description = "Allow access to the RDS database instance."
13-
name = "${var.project}-rds-inbound-access"
13+
name = "${var.prefix}-rds-inbound-access"
1414
vpc_id = module.vpc.vpc_id
1515

1616
ingress {
17+
# Existing ingress rule for Bastion and ECS services
1718
protocol = "tcp"
1819
from_port = 5432
1920
to_port = 5432
2021
security_groups = [
21-
aws_security_group.bastion.id,
22+
# aws_security_group.bastion.id,
2223
aws_security_group.ecs_service.id,
2324
]
2425
}
2526

27+
# ingress {
28+
# # New ingress rule for your local machine
29+
# protocol = "tcp"
30+
# from_port = 5432
31+
# to_port = 5432
32+
# cidr_blocks = [
33+
# "YOUR_PUBLIC_IP/32", # Replace YOUR_PUBLIC_IP with your actual public IP address
34+
# ]
35+
# }
36+
2637
tags = var.common_tags
2738
}
2839

40+
2941
resource "aws_db_instance" "main" {
3042
identifier = "${var.project}-db"
3143
db_name = var.db_name
3244
auto_minor_version_upgrade = true
3345
allocated_storage = var.rds_storage
3446
storage_type = "gp2"
3547
engine = "postgres"
36-
engine_version = "14"
48+
engine_version = var.engine_version
3749
instance_class = var.rds_instance
3850
db_subnet_group_name = aws_db_subnet_group.main.name
3951
password = var.db_password

ecs.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ resource "aws_ecs_task_definition" "api" {
269269
# ----------------------------
270270
# Security Group for ECS Service
271271
# ----------------------------
272+
#trivy:ignore:AVD-AWS-0104
272273
resource "aws_security_group" "ecs_service" {
273274
description = "Access for the ECS service"
274275
name = "${var.project}-ecs-service"
@@ -329,9 +330,9 @@ resource "aws_ecs_service" "api" {
329330
container_port = 8000
330331
}
331332
enable_execute_command = var.enable_execute_command
332-
333+
333334
health_check_grace_period_seconds = 300 # 5 minutes
334-
335+
335336
depends_on = [aws_lb_listener.api_https]
336337

337338
tags = var.common_tags

iam.tf

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ resource "tls_private_key" "pk" {
3232
rsa_bits = 4096
3333
}
3434

35-
resource "aws_key_pair" "kp" {
36-
key_name = "${var.project}-${var.bastion_key_name}" # Create "myKey" to AWS!!var.bastion_key_name
37-
public_key = tls_private_key.pk.public_key_openssh
38-
39-
provisioner "local-exec" { # Create "myKey.pem" to your computer!!
40-
command = "echo '${tls_private_key.pk.private_key_pem}' > ./${var.project}-myKey.pem"
41-
}
42-
}
4335

4436
resource "aws_iam_policy" "AppApiCi-proxy" {
4537
name = "${var.project}-AppApi-CI-proxy"

load_balancer.tf

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
#trivy:ignore:AVD-AWS-0053
12
resource "aws_lb" "api" {
2-
name = "${var.project}-main"
3-
load_balancer_type = "application"
4-
subnets = module.vpc.public_subnets
5-
6-
security_groups = [aws_security_group.lb.id]
3+
name = "${var.project}-main"
4+
load_balancer_type = "application"
5+
subnets = module.vpc.public_subnets
6+
drop_invalid_header_fields = true
7+
security_groups = [aws_security_group.lb.id]
78

89
tags = var.common_tags
910
}
@@ -72,7 +73,7 @@ resource "aws_lb_listener_rule" "host_header_rule" {
7273
}
7374
}
7475

75-
76+
#trivy:ignore:AVD-AWS-0104
7677
resource "aws_security_group" "lb" {
7778
description = "Allow access to Application Load Balancer"
7879
name = "${var.project}-lb"
@@ -83,13 +84,15 @@ resource "aws_security_group" "lb" {
8384
protocol = "tcp"
8485
from_port = 80
8586
to_port = 80
86-
cidr_blocks = ["0.0.0.0/0"]
87+
cidr_blocks = var.private ? [var.my_ip] : ["0.0.0.0/0"] # Conditional ingress rule
88+
8789
}
8890
ingress {
8991
protocol = "tcp"
9092
from_port = 443
9193
to_port = 443
92-
cidr_blocks = ["0.0.0.0/0"]
94+
cidr_blocks = var.private ? [var.my_ip] : ["0.0.0.0/0"] # Conditional ingress rule
95+
9396
}
9497

9598
egress {
@@ -98,6 +101,8 @@ resource "aws_security_group" "lb" {
98101
to_port = 8000
99102
cidr_blocks = ["0.0.0.0/0"]
100103
}
101-
104+
lifecycle {
105+
create_before_destroy = true
106+
}
102107
tags = var.common_tags
103108
}

0 commit comments

Comments
 (0)