Skip to content

Commit e134625

Browse files
authored
Merge pull request #5 from Aswin-Vijayan/master
Added variables
2 parents 6e4d991 + fcb9540 commit e134625

File tree

5 files changed

+84
-11
lines changed

5 files changed

+84
-11
lines changed

environments/dev/rds/main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ provider "aws" {
55
module "rds" {
66
source = "../../../modules/rds"
77
region = var.region
8+
db_engine = var.db_engine
9+
db_storage_type = var.db_storage_type
810
db_username = var.db_username
911
set_secret_manager_password = var.set_secret_manager_password
1012
set_db_password = var.set_db_password
@@ -13,6 +15,9 @@ module "rds" {
1315
db_instance_class = var.db_instance_class
1416
db_storage_size = var.db_storage_size
1517
sg_name = var.sg_name
18+
from_port = var.from_port
19+
to_port = var.to_port
20+
protocol = var.protocol
1621
cidr_block = var.cidr_block
1722
backup_retention_period = var.backup_retention_period
1823
multi_az = var.multi_az
@@ -21,6 +26,7 @@ module "rds" {
2126
publicly_accessible = var.publicly_accessible
2227
skip_final_snapshot = var.skip_final_snapshot
2328
apply_immediately = var.apply_immediately
29+
name = var.name
2430
owner = var.owner
2531
cost_center = var.cost_center
2632
environment = var.environment

environments/dev/rds/variables.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,35 @@ variable "apply_immediately" {
113113
description = "Apply changes immediately to the RDS instance."
114114
type = bool
115115
}
116+
117+
variable "db_engine" {
118+
description = "The database engine"
119+
type = string
120+
}
121+
122+
variable "db_storage_type" {
123+
description = "The storage type for the database"
124+
type = string
125+
}
126+
127+
variable "from_port" {
128+
description = "The starting port for ingress rules"
129+
type = number
130+
}
131+
132+
variable "to_port" {
133+
description = "The ending port for ingress rules"
134+
type = number
135+
}
136+
137+
variable "protocol" {
138+
description = "The protocol for ingress rules"
139+
type = string
140+
}
141+
142+
variable "name" {
143+
description = "The name attribute"
144+
type = string
145+
}
146+
147+

modules/rds/main.tf

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ resource "aws_security_group" "rds_security_group" {
44
description = "Security group for RDS instance"
55

66
ingress {
7-
from_port = 3306
8-
to_port = 3306
9-
protocol = "tcp"
7+
from_port = var.from_port
8+
to_port = var.to_port
9+
protocol = var.protocol
1010
cidr_blocks = var.cidr_block
1111
}
1212

1313
egress {
1414
from_port = 0
1515
to_port = 0
1616
protocol = "-1"
17-
cidr_blocks = var.cidr_block
17+
cidr_blocks = ["0.0.0.0/0"]
1818
}
1919

2020
tags = merge(
2121
{
22-
Name = "petclinic-alb-sg",
22+
Name = "${var.name}-sg",
2323
Environment = var.environment,
2424
Owner = var.owner,
2525
CostCenter = var.cost_center,
@@ -31,11 +31,10 @@ resource "aws_security_group" "rds_security_group" {
3131

3232
resource "aws_db_instance" "rds_instance" {
3333
identifier = var.db_name
34-
engine = "mysql"
34+
engine = var.db_engine
3535
instance_class = var.db_instance_class
3636
allocated_storage = var.db_storage_size
37-
storage_type = "gp2"
38-
# manage_master_user_password = var.set_secret_manager_password ? true : false
37+
storage_type = var.db_storage_type
3938
manage_master_user_password = var.set_secret_manager_password ? true : null
4039
username = var.db_username
4140
password = var.set_db_password ? var.db_password : null
@@ -51,7 +50,7 @@ resource "aws_db_instance" "rds_instance" {
5150

5251
tags = merge(
5352
{
54-
Name = "petclinic-rds"
53+
Name = var.name,
5554
Environment = var.environment,
5655
Owner = var.owner,
5756
CostCenter = var.cost_center,

modules/rds/variables.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,33 @@ variable "apply_immediately" {
113113
description = "Apply changes immediately to the RDS instance."
114114
type = bool
115115
}
116+
117+
variable "db_engine" {
118+
description = "The database engine"
119+
type = string
120+
}
121+
122+
variable "db_storage_type" {
123+
description = "The storage type for the database"
124+
type = string
125+
}
126+
127+
variable "from_port" {
128+
description = "The starting port for ingress rules"
129+
type = number
130+
}
131+
132+
variable "to_port" {
133+
description = "The ending port for ingress rules"
134+
type = number
135+
}
136+
137+
variable "protocol" {
138+
description = "The protocol for ingress rules"
139+
type = string
140+
}
141+
142+
variable "name" {
143+
description = "The name attribute"
144+
type = string
145+
}

vars/dev/rds.tfvars

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
region = "us-west-2"
2+
db_engine = "mysql"
3+
db_storage_type = "gp2"
24
db_username = "petclinic"
35
db_name = "petclinic-mysql-rds"
46
db_instance_class = "db.t2.micro"
57
db_storage_size = 10
6-
set_secret_manager_password = true
7-
set_db_password = false
8+
set_secret_manager_password = false
9+
set_db_password = true
810
db_password = "rdssecret"
11+
from_port = 3306
12+
to_port = 3306
13+
protocol = "tcp"
914
sg_name = "rds-security-group"
1015
cidr_block = ["0.0.0.0/0"]
1116
backup_retention_period = 7
@@ -15,6 +20,7 @@ copy_tags_to_snapshot = true
1520
publicly_accessible = true
1621
skip_final_snapshot = true
1722
apply_immediately = true
23+
name = "petclinic-rds"
1824
owner = "Techiescamp"
1925
environment = "dev"
2026
cost_center = "project-pet-clinic"

0 commit comments

Comments
 (0)