Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Separated maintenance window setting for cluster and instances #106

Closed
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ Terraform documentation is generated automatically using [pre-commit hooks](http
| port | The port on which to accept connections | `string` | `""` | no |
| predefined\_metric\_type | The metric type to scale on. Valid values are RDSReaderAverageCPUUtilization and RDSReaderAverageDatabaseConnections. | `string` | `"RDSReaderAverageCPUUtilization"` | no |
| preferred\_backup\_window | When to perform DB backups | `string` | `"02:00-03:00"` | no |
| preferred\_maintenance\_window | When to perform DB maintenance | `string` | `"sun:05:00-sun:06:00"` | no |
| preferred\_maintenance\_window | When to perform DB maintenance - Deprecated use specific cluster/instance maintenance window instead| `string` | `"sun:05:00-sun:06:00"` | no |
| preferred\_cluster_maintenance\_window | When to perform DB maintenance on the cluster | `string` | `"sun:05:00-sun:06:00"` | no |
| preferred\_instance_maintenance\_window | When to perform DB maintenance on the instances| `string` | `"sun:05:00-sun:06:00"` | no |
| publicly\_accessible | Whether the DB should have a public IP address | `bool` | `false` | no |
| replica\_count | Number of reader nodes to create. If `replica_scale_enable` is `true`, the value of `replica_scale_min` is used instead. | `number` | `1` | no |
| replica\_scale\_connections | Average number of connections to trigger autoscaling at. Default value is 70% of db.r4.large's default max\_connections | `number` | `700` | no |
Expand Down
36 changes: 19 additions & 17 deletions examples/advanced/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@ data "aws_subnet_ids" "all" {
# RDS Aurora
#############
module "aurora" {
source = "../../"
name = "aurora-example"
engine = "aurora-postgresql"
engine_version = "10.4"
subnets = data.aws_subnet_ids.all.ids
vpc_id = data.aws_vpc.default.id
replica_count = 1
replica_scale_enabled = true
replica_scale_min = 1
replica_scale_max = 5
monitoring_interval = 60
instance_type = "db.r4.large"
instance_type_replica = "db.t3.large"
apply_immediately = true
skip_final_snapshot = true
db_parameter_group_name = aws_db_parameter_group.aurora_db_postgres96_parameter_group.id
db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.aurora_cluster_postgres96_parameter_group.id
source = "../../"
name = "aurora-example"
engine = "aurora-postgresql"
engine_version = "10.4"
subnets = data.aws_subnet_ids.all.ids
vpc_id = data.aws_vpc.default.id
replica_count = 1
replica_scale_enabled = true
replica_scale_min = 1
replica_scale_max = 5
monitoring_interval = 60
preferred_cluster_maintenance_window = "wed:04:30-wed:05:00"
preferred_instance_maintenance_window = "wed:04:00-wed:04:30"
instance_type = "db.r4.large"
instance_type_replica = "db.t3.large"
apply_immediately = true
skip_final_snapshot = true
db_parameter_group_name = aws_db_parameter_group.aurora_db_postgres96_parameter_group.id
db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.aurora_cluster_postgres96_parameter_group.id
# enabled_cloudwatch_logs_exports = ["audit", "error", "general", "slowquery"]
}

Expand Down
1 change: 1 addition & 0 deletions examples/mysql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module "aurora" {
iam_database_authentication_enabled = true
enabled_cloudwatch_logs_exports = ["audit", "error", "general", "slowquery"]
allowed_cidr_blocks = ["10.20.0.0/20", "20.20.0.0/20"]
preferred_maintenance_window = "wed:04:00-wed:04:30"

create_security_group = true
}
Expand Down
8 changes: 6 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ locals {
db_subnet_group_name = var.db_subnet_group_name == "" ? join("", aws_db_subnet_group.this.*.name) : var.db_subnet_group_name
backtrack_window = (var.engine == "aurora-mysql" || var.engine == "aurora") && var.engine_mode != "serverless" ? var.backtrack_window : 0


preferred_cluster_maintenance_window = var.preferred_maintenance_window == "" ? var.preferred_cluster_maintenance_window : var.preferred_maintenance_window
preferred_instance_maintenance_window = var.preferred_maintenance_window == "" ? var.preferred_instance_maintenance_window : var.preferred_maintenance_window

rds_enhanced_monitoring_arn = var.create_monitoring_role ? join("", aws_iam_role.rds_enhanced_monitoring.*.arn) : var.monitoring_role_arn
rds_enhanced_monitoring_name = join("", aws_iam_role.rds_enhanced_monitoring.*.name)

Expand Down Expand Up @@ -52,7 +56,7 @@ resource "aws_rds_cluster" "this" {
deletion_protection = var.deletion_protection
backup_retention_period = var.backup_retention_period
preferred_backup_window = var.preferred_backup_window
preferred_maintenance_window = var.preferred_maintenance_window
preferred_maintenance_window = local.preferred_cluster_maintenance_window
port = local.port
db_subnet_group_name = local.db_subnet_group_name
vpc_security_group_ids = compact(concat(aws_security_group.this.*.id, var.vpc_security_group_ids))
Expand Down Expand Up @@ -93,7 +97,7 @@ resource "aws_rds_cluster_instance" "this" {
publicly_accessible = length(var.instances_parameters) > count.index ? lookup(var.instances_parameters[count.index], "publicly_accessible", var.publicly_accessible) : var.publicly_accessible
db_subnet_group_name = local.db_subnet_group_name
db_parameter_group_name = var.db_parameter_group_name
preferred_maintenance_window = var.preferred_maintenance_window
preferred_maintenance_window = local.preferred_instance_maintenance_window
apply_immediately = var.apply_immediately
monitoring_role_arn = local.rds_enhanced_monitoring_arn
monitoring_interval = var.monitoring_interval
Expand Down
14 changes: 13 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,19 @@ variable "preferred_backup_window" {
}

variable "preferred_maintenance_window" {
description = "When to perform DB maintenance"
description = "DEPRECATED, use cluster/instance maintenance window instead. Kept a little longer for backwards compatibility."
type = string
default = ""
}

variable "preferred_cluster_maintenance_window" {
description = "When to perform maintenance on the cluster"
type = string
default = "sun:05:00-sun:06:00"
}

variable "preferred_instance_maintenance_window" {
description = "When to perform maintenance on the instances"
type = string
default = "sun:05:00-sun:06:00"
}
Expand Down