Skip to content

Commit c9c0ceb

Browse files
author
rohit-ng
committed
feat: add postgres rds module
1 parent 6b1984a commit c9c0ceb

File tree

2 files changed

+226
-0
lines changed

2 files changed

+226
-0
lines changed

main.tf

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
locals {
2+
kong_container_image = "kong:3.7.1-ubuntu"
3+
name = "kong-postgres"
4+
db_identifier = "${local.name}-01"
5+
rds_engine = "postgres"
6+
storage_encrypted = true
7+
storage_type = "gp3"
8+
9+
postgres = {
10+
engine_version = 16.3
11+
engine_family = "postgres16"
12+
major_engine_version = 16
13+
port = 5432
14+
}
15+
16+
default_tags = {
17+
ManagedBy = "Terraform"
18+
}
19+
}
20+
21+
data "aws_vpc" "vpc" {
22+
id = var.vpc_id
23+
}
24+
25+
26+
module "postgres-security-group" {
27+
source = "terraform-aws-modules/security-group/aws"
28+
version = "~> 5.1.2"
29+
30+
name = local.name
31+
description = "Allow all traffic within vpc"
32+
vpc_id = var.vpc_id
33+
34+
ingress_with_cidr_blocks = [
35+
{
36+
from_port = 0
37+
to_port = 5432
38+
protocol = "tcp"
39+
description = "PostgreSQL access from within VPC"
40+
cidr_blocks = data.aws_vpc.vpc.cidr_block
41+
},
42+
]
43+
44+
tags = merge(local.default_tags, var.postgres_sg_tags)
45+
}
46+
47+
module "kong-rds" {
48+
source = "terraform-aws-modules/rds/aws"
49+
version = "~> 6.7.0"
50+
51+
identifier = local.db_identifier
52+
engine = local.rds_engine
53+
engine_version = local.postgres.engine_version
54+
family = local.postgres.engine_family
55+
major_engine_version = local.postgres.major_engine_version
56+
instance_class = var.rds_instance_class
57+
58+
storage_encrypted = local.storage_encrypted
59+
storage_type = local.storage_type
60+
allocated_storage = var.db_allocated_storage
61+
max_allocated_storage = var.db_max_allocated_storage
62+
multi_az = var.multi_az
63+
64+
manage_master_user_password = var.manage_master_user_password
65+
db_name = var.db_name
66+
username = var.db_username
67+
port = local.postgres.port
68+
password = var.db_password
69+
70+
backup_retention_period = var.backup_retention_period
71+
backup_window = var.backup_window
72+
deletion_protection = var.deletion_protection
73+
maintenance_window = var.maintenance_window
74+
75+
vpc_security_group_ids = [module.postgres-security-group.security_group_id]
76+
create_db_subnet_group = var.create_db_subnet_group
77+
subnet_ids = var.private_subnet_ids
78+
performance_insights_enabled = var.performance_insights_enabled
79+
performance_insights_retention_period = var.performance_insights_retention_period
80+
81+
tags = merge(local.default_tags, var.rds_db_tags)
82+
}
83+

variables.tf

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
variable "cluster_name" {
2+
description = "Name of the cluster"
3+
type = string
4+
}
5+
6+
variable "private_subnet_ids" {
7+
description = "List of private subnet id"
8+
type = list(string)
9+
}
10+
11+
variable "vpc_id" {
12+
description = "The ID of the VPC"
13+
type = string
14+
}
15+
16+
variable "rds_instance_class" {
17+
description = "The instance class to use"
18+
type = string
19+
default = "db.t3.micro"
20+
}
21+
22+
variable "db_allocated_storage" {
23+
description = "The amount of allocated storage in GBs"
24+
type = number
25+
default = 20
26+
}
27+
28+
variable "db_max_allocated_storage" {
29+
description = "The maximum amount of allocated storage in GBs"
30+
type = number
31+
default = 100
32+
}
33+
34+
variable "manage_master_user_password" {
35+
description = "Whether to manage master user password"
36+
type = bool
37+
default = false
38+
}
39+
40+
variable "backup_retention_period" {
41+
description = "The number of days to retain backups"
42+
type = number
43+
default = 1
44+
}
45+
46+
variable "skip_final_snapshot" {
47+
description = "Whether to skip the final snapshot"
48+
type = bool
49+
default = true
50+
}
51+
52+
variable "deletion_protection" {
53+
description = "Whether to enable deletion protection"
54+
type = bool
55+
default = false
56+
}
57+
58+
variable "create_db_subnet_group" {
59+
description = "Whether to create a DB subnet group"
60+
type = bool
61+
default = true
62+
}
63+
64+
variable "performance_insights_enabled" {
65+
description = "Whether to enable performance insights"
66+
type = bool
67+
default = true
68+
}
69+
70+
variable "performance_insights_retention_period" {
71+
description = "The retention period for performance insights"
72+
type = number
73+
default = 7
74+
}
75+
76+
variable "db_name" {
77+
description = "Database name"
78+
type = string
79+
default = "kong"
80+
}
81+
82+
variable "db_username" {
83+
description = "Username for database"
84+
type = string
85+
default = "kong"
86+
}
87+
88+
variable "db_password" {
89+
description = "Username for database"
90+
type = string
91+
default = "defaultpassword"
92+
}
93+
94+
variable "private_subnet_ids" {
95+
description = "List of private subnet id"
96+
type = list(string)
97+
}
98+
99+
variable "vpc_id" {
100+
description = "The ID of the VPC"
101+
type = string
102+
}
103+
104+
variable "rds_db_tags" {
105+
description = "List of tags"
106+
type = map(string)
107+
default = {}
108+
}
109+
110+
variable "postgres_sg_tags" {
111+
description = "List of tags"
112+
type = map(string)
113+
default = {}
114+
}
115+
116+
variable "multi_az" {
117+
description = "Specifies if the RDS instance is multi-AZ"
118+
type = bool
119+
default = false
120+
}
121+
122+
variable "backup_window" {
123+
description = "The daily time range (in UTC) during which automated backups are created if they are enabled"
124+
type = string
125+
default = null
126+
}
127+
128+
variable "maintenance_window" {
129+
description = "The window to perform maintenance in.Syntax:ddd:hh24:mi-ddd:hh24:mi"
130+
type = string
131+
default = null
132+
}
133+
134+
variable "region" {
135+
description = "AWS region"
136+
type = string
137+
}
138+
139+
variable "postgres_db_name" {
140+
description = "Postgres database name"
141+
type = string
142+
default = "kong"
143+
}

0 commit comments

Comments
 (0)