From c74771de3006e308c693fbb1690c5a3e4e50317d Mon Sep 17 00:00:00 2001 From: Eric Millbrandt Date: Wed, 17 Feb 2021 18:33:50 -0500 Subject: [PATCH 1/2] fix: Specify the number of read replicas as one less that total instances (#190) --- CHANGELOG.md | 1 + README.md | 4 ++-- main.tf | 2 +- variables.tf | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ceb3db5..9674c33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +- fix: Specify the number of read replicas as one less that total instances ([#190](https://github.com/terraform-aws-modules/terraform-aws-rds-aurora/issues/190)) diff --git a/README.md b/README.md index 730c2a5..47afda4 100644 --- a/README.md +++ b/README.md @@ -153,8 +153,8 @@ Terraform documentation is generated automatically using [pre-commit hooks](http | replica\_scale\_cpu | CPU usage to trigger autoscaling at | `number` | `70` | no | | replica\_scale\_enabled | Whether to enable autoscaling for RDS Aurora (MySQL) read replicas | `bool` | `false` | no | | replica\_scale\_in\_cooldown | Cooldown in seconds before allowing further scaling operations after a scale in | `number` | `300` | no | -| replica\_scale\_max | Maximum number of replicas to allow scaling for | `number` | `0` | no | -| replica\_scale\_min | Minimum number of replicas to allow scaling for | `number` | `2` | no | +| replica\_scale\_max | Maximum number of read replicas to allow scaling for | `number` | `0` | no | +| replica\_scale\_min | Minimum number of read replicas to allow scaling for | `number` | `2` | no | | replica\_scale\_out\_cooldown | Cooldown in seconds before allowing further scaling operations after a scale out | `number` | `300` | no | | replication\_source\_identifier | ARN of a source DB cluster or DB instance if this DB cluster is to be created as a Read Replica. | `string` | `""` | no | | scaling\_configuration | Map of nested attributes with scaling properties. Only valid when engine\_mode is set to `serverless` | `map(string)` | `{}` | no | diff --git a/main.tf b/main.tf index fc01a84..5ea12e9 100644 --- a/main.tf +++ b/main.tf @@ -84,7 +84,7 @@ resource "aws_rds_cluster" "this" { } resource "aws_rds_cluster_instance" "this" { - count = var.create_cluster ? (var.replica_scale_enabled ? var.replica_scale_min : var.replica_count) : 0 + count = var.create_cluster ? (var.replica_scale_enabled ? var.replica_scale_min + 1: var.replica_count + 1) : 0 identifier = length(var.instances_parameters) > count.index ? lookup(var.instances_parameters[count.index], "instance_name", "${var.name}-${count.index + 1}") : "${var.name}-${count.index + 1}" cluster_identifier = element(concat(aws_rds_cluster.this.*.id, [""]), 0) diff --git a/variables.tf b/variables.tf index 7b391ab..a404239 100644 --- a/variables.tf +++ b/variables.tf @@ -239,13 +239,13 @@ variable "replica_scale_enabled" { } variable "replica_scale_max" { - description = "Maximum number of replicas to allow scaling for" + description = "Maximum number of read replicas to allow scaling for" type = number default = 0 } variable "replica_scale_min" { - description = "Minimum number of replicas to allow scaling for" + description = "Minimum number of read replicas to allow scaling for" type = number default = 2 } From cae691acb3096ab8681be9dd573bdef8cd523c7b Mon Sep 17 00:00:00 2001 From: emillbrandt Date: Thu, 15 Apr 2021 16:07:25 -0400 Subject: [PATCH 2/2] Lint --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index d76d806..e3731b2 100644 --- a/main.tf +++ b/main.tf @@ -110,7 +110,7 @@ resource "aws_rds_cluster" "this" { } resource "aws_rds_cluster_instance" "this" { - count = var.create_cluster ? (var.replica_scale_enabled ? var.replica_scale_min + 1: var.replica_count + 1) : 0 + count = var.create_cluster ? (var.replica_scale_enabled ? var.replica_scale_min + 1 : var.replica_count + 1) : 0 identifier = try(lookup(var.instances_parameters[count.index], "instance_name"), "${var.name}-${count.index + 1}") cluster_identifier = element(concat(aws_rds_cluster.this.*.id, [""]), 0)