Skip to content

Commit 15c8072

Browse files
committed
Fix db creation error
1 parent 79d884d commit 15c8072

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

modules/database/main.tf

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ module "db" {
66

77
engine = "postgres"
88
engine_version = var.postgres_version
9-
family = "postgres13"
10-
major_engine_version = "13"
9+
family = "postgres${var.postgres_version}"
10+
major_engine_version = var.postgres_version
1111
instance_class = var.instance_class
1212

1313
password = var.database_password
@@ -23,14 +23,17 @@ module "db" {
2323
multi_az = var.multi_az
2424
subnet_ids = var.database_subnet_ids
2525
vpc_security_group_ids = [aws_security_group.database.id]
26+
create_db_subnet_group = true
27+
db_subnet_group_name = "${var.db_identifier}-subnet-group"
2628

27-
maintenance_window = var.maintenance_window
28-
backup_window = var.backup_window
29-
29+
maintenance_window = var.maintenance_window
30+
backup_window = var.backup_window
3031
backup_retention_period = var.backup_retention_period
3132
skip_final_snapshot = true
3233

3334
tags = var.tags
35+
36+
depends_on = [aws_security_group.database]
3437
}
3538

3639
resource "aws_security_group" "database" {
@@ -44,5 +47,18 @@ resource "aws_security_group" "database" {
4447
security_groups = [var.eks_security_group_id]
4548
}
4649

47-
tags = var.tags
50+
egress {
51+
from_port = 0
52+
to_port = 0
53+
protocol = "-1"
54+
cidr_blocks = ["0.0.0.0/0"]
55+
}
56+
57+
tags = merge(var.tags, {
58+
Name = "${var.db_identifier}-sg"
59+
})
60+
61+
lifecycle {
62+
create_before_destroy = true
63+
}
4864
}

0 commit comments

Comments
 (0)