Skip to content

Commit

Permalink
Merge pull request #9 from ehenrik/main
Browse files Browse the repository at this point in the history
chore: add support for read replicas
  • Loading branch information
argoyle authored Jun 15, 2022
2 parents df9f0ab + e07b132 commit 81e0d5e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
14 changes: 14 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ resource "aws_rds_cluster_instance" "writer" {
monitoring_role_arn = var.enhanced_monitoring ? aws_iam_role.rds_enhanced_monitoring[0].arn : null
}


resource "aws_rds_cluster_instance" "reader" {
count = var.reader_instance_type ? 0 : 1
cluster_identifier = aws_rds_cluster.default.cluster_identifier
identifier = "${var.identifier}-reader"
instance_class = var.reader_instance_type
engine = aws_rds_cluster.default.engine
engine_version = aws_rds_cluster.default.engine_version
monitoring_interval = var.enhanced_monitoring ? 60 : 0
monitoring_role_arn = var.enhanced_monitoring ? aws_iam_role.rds_enhanced_monitoring[0].arn : null
promotion_tier = 1

}

resource "aws_rds_cluster_parameter_group" "cluster_parameters" {
family = "aurora-mysql5.7"
name = "${var.identifier}-cluster-parameters"
Expand Down
12 changes: 7 additions & 5 deletions secret.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ resource "aws_secretsmanager_secret_version" "aurora_secret_value" {

locals {
secret_value = {
DB_USERNAME = var.master_username
DB_PASSWORD = local.password
DB_NAME = aws_rds_cluster.default.cluster_identifier
DB_PORT = aws_rds_cluster.default.port
DB_HOST = aws_rds_cluster.default.endpoint
DB_USERNAME = var.master_username
DB_PASSWORD = local.password
DB_NAME = aws_rds_cluster.default.cluster_identifier
DB_PORT = aws_rds_cluster.default.port
DB_HOST = aws_rds_cluster.default.endpoint
DB_READER_HOST = local.reader_instance_endpoint
}
reader_instance_endpoint = var.reader_instance_type ? "" : aws_rds_cluster_instance.reader[0].endpoint
password = random_password.password.result
}

Expand Down
6 changes: 6 additions & 0 deletions vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,9 @@ variable "enhanced_monitoring" {
default = false
description = "Enable enhanced monitor on the instance"
}

variable "reader_instance_type" {
type = string
description = "Instance type of writers"
default = null
}

0 comments on commit 81e0d5e

Please sign in to comment.