Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions environments/dev/rds/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ provider "aws" {
module "rds" {
source = "../../../modules/rds"
region = var.region
db_engine = var.db_engine
db_storage_type = var.db_storage_type
db_username = var.db_username
set_secret_manager_password = var.set_secret_manager_password
set_db_password = var.set_db_password
Expand All @@ -13,6 +15,9 @@ module "rds" {
db_instance_class = var.db_instance_class
db_storage_size = var.db_storage_size
sg_name = var.sg_name
from_port = var.from_port
to_port = var.to_port
protocol = var.protocol
cidr_block = var.cidr_block
backup_retention_period = var.backup_retention_period
multi_az = var.multi_az
Expand All @@ -21,6 +26,7 @@ module "rds" {
publicly_accessible = var.publicly_accessible
skip_final_snapshot = var.skip_final_snapshot
apply_immediately = var.apply_immediately
name = var.name
owner = var.owner
cost_center = var.cost_center
environment = var.environment
Expand Down
32 changes: 32 additions & 0 deletions environments/dev/rds/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,35 @@ variable "apply_immediately" {
description = "Apply changes immediately to the RDS instance."
type = bool
}

variable "db_engine" {
description = "The database engine"
type = string
}

variable "db_storage_type" {
description = "The storage type for the database"
type = string
}

variable "from_port" {
description = "The starting port for ingress rules"
type = number
}

variable "to_port" {
description = "The ending port for ingress rules"
type = number
}

variable "protocol" {
description = "The protocol for ingress rules"
type = string
}

variable "name" {
description = "The name attribute"
type = string
}


17 changes: 8 additions & 9 deletions modules/rds/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ resource "aws_security_group" "rds_security_group" {
description = "Security group for RDS instance"

ingress {
from_port = 3306
to_port = 3306
protocol = "tcp"
from_port = var.from_port
to_port = var.to_port
protocol = var.protocol
cidr_blocks = var.cidr_block
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = var.cidr_block
cidr_blocks = ["0.0.0.0/0"]
}

tags = merge(
{
Name = "petclinic-alb-sg",
Name = "${var.name}-sg",
Environment = var.environment,
Owner = var.owner,
CostCenter = var.cost_center,
Expand All @@ -31,11 +31,10 @@ resource "aws_security_group" "rds_security_group" {

resource "aws_db_instance" "rds_instance" {
identifier = var.db_name
engine = "mysql"
engine = var.db_engine
instance_class = var.db_instance_class
allocated_storage = var.db_storage_size
storage_type = "gp2"
# manage_master_user_password = var.set_secret_manager_password ? true : false
storage_type = var.db_storage_type
manage_master_user_password = var.set_secret_manager_password ? true : null
username = var.db_username
password = var.set_db_password ? var.db_password : null
Expand All @@ -51,7 +50,7 @@ resource "aws_db_instance" "rds_instance" {

tags = merge(
{
Name = "petclinic-rds"
Name = var.name,
Environment = var.environment,
Owner = var.owner,
CostCenter = var.cost_center,
Expand Down
30 changes: 30 additions & 0 deletions modules/rds/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,33 @@ variable "apply_immediately" {
description = "Apply changes immediately to the RDS instance."
type = bool
}

variable "db_engine" {
description = "The database engine"
type = string
}

variable "db_storage_type" {
description = "The storage type for the database"
type = string
}

variable "from_port" {
description = "The starting port for ingress rules"
type = number
}

variable "to_port" {
description = "The ending port for ingress rules"
type = number
}

variable "protocol" {
description = "The protocol for ingress rules"
type = string
}

variable "name" {
description = "The name attribute"
type = string
}
10 changes: 8 additions & 2 deletions vars/dev/rds.tfvars
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
region = "us-west-2"
db_engine = "mysql"
db_storage_type = "gp2"
db_username = "petclinic"
db_name = "petclinic-mysql-rds"
db_instance_class = "db.t2.micro"
db_storage_size = 10
set_secret_manager_password = true
set_db_password = false
set_secret_manager_password = false
set_db_password = true
db_password = "rdssecret"
from_port = 3306
to_port = 3306
protocol = "tcp"
sg_name = "rds-security-group"
cidr_block = ["0.0.0.0/0"]
backup_retention_period = 7
Expand All @@ -15,6 +20,7 @@ copy_tags_to_snapshot = true
publicly_accessible = true
skip_final_snapshot = true
apply_immediately = true
name = "petclinic-rds"
owner = "Techiescamp"
environment = "dev"
cost_center = "project-pet-clinic"
Expand Down