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: Adding support for serverlessv2 scaling configuration #15

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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,15 @@ No modules.
| <a name="input_final_snapshot_identifier_prefix"></a> [final\_snapshot\_identifier\_prefix](#input\_final\_snapshot\_identifier\_prefix) | The prefix name to use when creating a final snapshot on cluster destroy, appends a random 8 digits to name to ensure it's unique too. | `string` | `"final"` | no |
| <a name="input_identifier"></a> [identifier](#input\_identifier) | Cluster identifier | `string` | `"aurora"` | no |
| <a name="input_instance_class"></a> [instance\_class](#input\_instance\_class) | Instance type to use at replica instance | `string` | `"db.r5.large"` | no |
| <a name="input_max_capacity"></a> [max\_capacity](#input\_max\_capacity) | Requires serverless\_scaling to be set to true. The maximum number of Aurora capacity units (ACUs) for a DB instance in an Aurora Serverless v2 cluster. | `string` | `"2.0"` | no |
| <a name="input_min_capacity"></a> [min\_capacity](#input\_min\_capacity) | Requires serverless\_scaling to be set to true. The minimum number of Aurora capacity units (ACUs) for a DB instance in an Aurora Serverless v2 cluster | `string` | `"1.0"` | no |
| <a name="input_monitoring_interval"></a> [monitoring\_interval](#input\_monitoring\_interval) | Enhanced Monitoring interval in seconds | `number` | `1` | no |
| <a name="input_name"></a> [name](#input\_name) | Prefix for resource names | `string` | `"aurora"` | no |
| <a name="input_port"></a> [port](#input\_port) | The port on which to accept connections | `string` | `""` | no |
| <a name="input_preferred_backup_window"></a> [preferred\_backup\_window](#input\_preferred\_backup\_window) | When to perform DB backups | `string` | `"02:00-03:00"` | no |
| <a name="input_primary_instance_count"></a> [primary\_instance\_count](#input\_primary\_instance\_count) | instance count for primary Aurora cluster | `number` | `2` | no |
| <a name="input_secondary_instance_count"></a> [secondary\_instance\_count](#input\_secondary\_instance\_count) | instance count for secondary Aurora cluster | `number` | `1` | no |
| <a name="input_serverless_scaling"></a> [serverless\_scaling](#input\_serverless\_scaling) | Boolean to enable or disable Serverless v2 autoscaling for the cluster | `bool` | `false` | no |
| <a name="input_setup_as_secondary"></a> [setup\_as\_secondary](#input\_setup\_as\_secondary) | Setup aws\_rds\_cluster.primary Terraform resource as Secondary Aurora cluster after an unplanned Aurora Global DB failover | `bool` | `false` | no |
| <a name="input_setup_globaldb"></a> [setup\_globaldb](#input\_setup\_globaldb) | Setup Aurora Global Database with 1 Primary and 1 X-region Secondary cluster | `bool` | `false` | no |
| <a name="input_skip_final_snapshot"></a> [skip\_final\_snapshot](#input\_skip\_final\_snapshot) | skip creating a final snapshot before deleting the DB | `bool` | `true` | no |
Expand Down
18 changes: 18 additions & 0 deletions deploy/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ variable "password" {
description = "If no password is provided, a random password will be generated"
}

variable "serverless_scaling" {
description = "Boolean to enable or disable Serverless v2 autoscaling for the cluster"
type = bool
default = false
}

variable "min_capacity" {
description = "The minimum number of Aurora capacity units (ACUs) for a DB instance in an Aurora Serverless v2 cluster"
type = string
default = "1.0"
}

variable "max_capacity" {
description = "The maximum number of Aurora capacity units (ACUs) for a DB instance in an Aurora Serverless v2 cluster."
type = string
default = "2.0"
}

/*
variable "tags" {
default = {}
Expand Down
33 changes: 21 additions & 12 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,27 @@ resource "aws_rds_global_cluster" "globaldb" {
}

resource "aws_rds_cluster" "primary" {
provider = aws.primary
global_cluster_identifier = var.setup_globaldb ? aws_rds_global_cluster.globaldb[0].id : null
cluster_identifier = "${var.identifier}-${var.region}"
engine = var.engine
engine_version = var.engine == "aurora-postgresql" ? var.engine_version_pg : var.engine_version_mysql
allow_major_version_upgrade = var.allow_major_version_upgrade
availability_zones = [data.aws_availability_zones.region_p.names[0], data.aws_availability_zones.region_p.names[1], data.aws_availability_zones.region_p.names[2]]
db_subnet_group_name = aws_db_subnet_group.private_p.name
port = var.port == "" ? var.engine == "aurora-postgresql" ? "5432" : "3306" : var.port
database_name = var.setup_as_secondary || (var.snapshot_identifier != "") ? null : var.database_name
master_username = var.setup_as_secondary || (var.snapshot_identifier != "") ? null : var.username
master_password = var.setup_as_secondary || (var.snapshot_identifier != "") ? null : (var.password == "" ? random_password.master_password.result : var.password)
provider = aws.primary
global_cluster_identifier = var.setup_globaldb ? aws_rds_global_cluster.globaldb[0].id : null
cluster_identifier = "${var.identifier}-${var.region}"
engine = var.engine
engine_version = var.engine == "aurora-postgresql" ? var.engine_version_pg : var.engine_version_mysql
allow_major_version_upgrade = var.allow_major_version_upgrade
availability_zones = [data.aws_availability_zones.region_p.names[0], data.aws_availability_zones.region_p.names[1], data.aws_availability_zones.region_p.names[2]]
db_subnet_group_name = aws_db_subnet_group.private_p.name
port = var.port == "" ? var.engine == "aurora-postgresql" ? "5432" : "3306" : var.port
database_name = var.setup_as_secondary || (var.snapshot_identifier != "") ? null : var.database_name
master_username = var.setup_as_secondary || (var.snapshot_identifier != "") ? null : var.username
master_password = var.setup_as_secondary || (var.snapshot_identifier != "") ? null : (var.password == "" ? random_password.master_password.result : var.password)

dynamic "serverlessv2_scaling_configuration" {
for_each = var.serverless_scaling ? [1] : []
content {
max_capacity = var.max_capacity
min_capacity = var.min_capacity
}
}

db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.aurora_cluster_parameter_group_p.id
db_instance_parameter_group_name = var.allow_major_version_upgrade ? aws_db_parameter_group.aurora_db_parameter_group_p.id : null
backup_retention_period = var.backup_retention_period
Expand Down
18 changes: 18 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ variable "database_name" {
default = "mydb"
}

variable "serverless_scaling" {
description = "Boolean to enable or disable Serverless v2 autoscaling for the cluster"
type = bool
default = false
}

variable "min_capacity" {
description = "Requires serverless_scaling to be set to true. The minimum number of Aurora capacity units (ACUs) for a DB instance in an Aurora Serverless v2 cluster"
type = string
default = "1.0"
}

variable "max_capacity" {
description = "Requires serverless_scaling to be set to true. The maximum number of Aurora capacity units (ACUs) for a DB instance in an Aurora Serverless v2 cluster."
type = string
default = "2.0"
}

variable "username" {
description = "Master DB username"
type = string
Expand Down