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

Changing replica_count causes all instances to be recreated #151

Closed
szpuni opened this issue Oct 8, 2020 · 2 comments · Fixed by #243
Closed

Changing replica_count causes all instances to be recreated #151

szpuni opened this issue Oct 8, 2020 · 2 comments · Fixed by #243

Comments

@szpuni
Copy link

szpuni commented Oct 8, 2020

For some reason when you change replica_count and then hit apply all instances are being replaced.
I was trying to see if Aurora will actually add and remove instances when you change amount of available instances but all instances are being replaced even tho you either added or removed 1 instance.

module "rds-aurora" {
  source                          = "terraform-aws-modules/rds-aurora/aws"
  version                         = "2.27.0"
  instance_type                   = var.instance_type
  name                            = "${var.account_name}-${var.environment}-${var.db_name}"
  vpc_id                          = data.terraform_remote_state.vpc.outputs.vpc_id
  subnets                         = data.terraform_remote_state.vpc.outputs.database_subnet_id
  engine                          = var.rds_engine_type
  engine_mode                     = var.rds_engine_mode
  engine_version                  = var.rds_engine_version
  storage_encrypted               = var.rds_storage_encrypted
  kms_key_id                      = var.rds_storage_encrypted ? aws_kms_key.key.arn : null
  preferred_maintenance_window    = var.rds_maintenance_window
  preferred_backup_window         = var.rds_backup_window
  auto_minor_version_upgrade      = true
  username                        = ..........
  password                        = ..........
  db_parameter_group_name         = "${var.account_name}-${var.environment}-${var.db_name}-instance"
  db_cluster_parameter_group_name = "${var.account_name}-${var.environment}-${var.db_name}-cluster"
  replica_count                   = var.rds_read_replica_count
  instance_type_replica           = var.rds_read_replica_instance_type != "" ? var.rds_read_replica_instance_type : var.instance_type
  tags = {
    Environment = var.environment
    Name        = "${var.account_name}-${var.environment}-${var.db_name}"
    Terraform   = "true"
  }
}

Each time I update replica_count from 1 to 2 or from 2 to 3 or from 3 to 2 all instances are being removed.

After investigating logs further noticed that entire cluster is removed and only thing that changed between both runs is above mentioned value.

Terraform apply truncated output below:

module.rds-aurora.module.rds-aurora.random_id.snapshot_identifier: Refreshing state... [id=]
module.rds-aurora.module.rds-aurora.random_password.master_password: Refreshing state... [id=none]
module.rds-aurora.random_password.this: Refreshing state... [id=none]
module.rds-aurora.aws_kms_key.key: Refreshing state... [id=-]
module.rds-aurora.data.aws_region.current: Refreshing state...
module.rds-aurora.aws_db_parameter_group.this: Refreshing state... [id=prod-portals-instance]
module.rds-aurora.data.aws_caller_identity.current: Refreshing state...
module.rds-aurora.module.rds-aurora.data.aws_iam_policy_document.monitoring_rds_assume_role: Refreshing state...
module.rds-aurora.aws_rds_cluster_parameter_group.this: Refreshing state... [id=prod-portals-cluster]
module.rds-aurora.data.terraform_remote_state.vpc: Refreshing state...
module.rds-aurora.data.aws_iam_policy_document.policy: Refreshing state...
module.rds-aurora.aws_kms_alias.kms_alias: Refreshing state... [id=alias/prod-portals-aurora]
module.rds-aurora.module.rds-aurora.aws_db_subnet_group.this[0]: Refreshing state... [id=prod-portals]
module.rds-aurora.module.rds-aurora.aws_security_group.this[0]: Refreshing state... [id=sg-]
module.rds-aurora.aws_security_group_rule.rule_1: Refreshing state... [id=sgrule-]
module.rds-aurora.module.rds-aurora.aws_rds_cluster.this: Refreshing state... [id=prod-portals]
module.rds-aurora.module.rds-aurora.aws_rds_cluster_instance.this[2]: Refreshing state... [id=prod-portals-3]
module.rds-aurora.module.rds-aurora.aws_rds_cluster_instance.this[0]: Refreshing state... [id=prod-portals-1]
module.rds-aurora.module.rds-aurora.aws_rds_cluster_instance.this[1]: Refreshing state... [id=prod-portals-2]
module.rds-aurora.module.rds-aurora.aws_rds_cluster_instance.this[1]: Destroying... [id=prod-portals-2]
module.rds-aurora.module.rds-aurora.aws_rds_cluster_instance.this[2]: Destroying... [id=prod-portals-3]
module.rds-aurora.module.rds-aurora.aws_rds_cluster_instance.this[0]: Destroying... [id=prod-portals-1]
module.rds-aurora.module.rds-aurora.aws_rds_cluster_instance.this[0]: Destruction complete after 1m56s
module.rds-aurora.module.rds-aurora.aws_rds_cluster_instance.this[1]: Destruction complete after 3m32s
module.rds-aurora.module.rds-aurora.aws_rds_cluster_instance.this[2]: Destruction complete after 3m43s
module.rds-aurora.module.rds-aurora.aws_rds_cluster.this: Destroying... [id=prod-portals]
module.rds-aurora.module.rds-aurora.aws_rds_cluster.this: Destruction complete after 1m46s
module.rds-aurora.module.rds-aurora.aws_rds_cluster.this: Creating...
module.rds-aurora.module.rds-aurora.aws_rds_cluster.this: Creation complete after 1m6s [id=prod-portals]
module.rds-aurora.module.rds-aurora.aws_rds_cluster_instance.this[0]: Creating...
module.rds-aurora.module.rds-aurora.aws_rds_cluster_instance.this[1]: Creating...
@szpuni
Copy link
Author

szpuni commented Oct 8, 2020

Looks like problem is with engine_mode setting which for some reason is set to provisioned and I deploy version perallelquery.

  # module.rds-aurora.module.rds-aurora.aws_rds_cluster.this must be replaced
-/+ resource "aws_rds_cluster" "this" {
        apply_immediately                   = false
      ~ arn                                 = "arn:aws:rds:::cluster:aurora_cluster" -> (known after apply)
      ~ availability_zones                  = [
          - "ca-central-1a",
          - "ca-central-1b",
          - "ca-central-1d",
        ] -> (known after apply)
        backtrack_window                    = 0
        backup_retention_period             = 7
        cluster_identifier                  = "aurora_cluster"
      + cluster_identifier_prefix           = (known after apply)
      ~ cluster_members                     = [
          - "instance1",
          - "instance2",
        ] -> (known after apply)
      ~ cluster_resource_id                 = "cluster-" -> (known after apply)
        copy_tags_to_snapshot               = false
      + database_name                       = (known after apply)
        db_cluster_parameter_group_name     = "instancecluster"
        db_subnet_group_name                = "aurora_cluster"
        deletion_protection                 = false
        enable_http_endpoint                = false
      - enabled_cloudwatch_logs_exports     = [] -> null
      ~ endpoint                            = "aurora_cluster.rds.amazonaws.com" -> (known after apply)
        engine                              = "aurora"
      ~ engine_mode                         = "provisioned" -> "parallelquery" # forces replacement
        engine_version                      = "5.6.mysql_aurora.1.23.0"
        final_snapshot_identifier           = "final-instance"
      ~ hosted_zone_id                      = "" -> (known after apply)
        iam_database_authentication_enabled = false
      - iam_roles                           = [] -> null
      ~ id                                  = "aurora_cluster" -> (known after apply)
        kms_key_id                          = ""
        master_password                     = (sensitive value)
        master_username                     = ""
        port                                = 3306
        preferred_backup_window             = "08:00-09:00"
        preferred_maintenance_window        = "sat:10:00-sat:11:00"
      ~ reader_endpoint                     = "aurora_cluster.rds.amazonaws.com" -> (known after apply)
        skip_final_snapshot                 = false
        storage_encrypted                   = true
        tags                                = {
            "Environment" = "prod"
            "Name"        = "aurora_cluster"
            "Terraform"   = "true"
        }
        vpc_security_group_ids              = [
            "sg-",
        ]
    }

According to documentation this value defaults to provisioned which is what I see here too but cluster is provisioned as parallelquery.

Looks like instance count have nothing to do with this and trying to run code with that setting even without any changes tries to replace entire cluster.

terraform version
Terraform v0.12.28
+ provider.aws v3.9.0
+ provider.random v2.3.0

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
1 participant