State file not changing a block

Hi

I was using the official aws_rds_cluster Resource to create a RDS. Initially I create an aurora Server which required the serverlessv2_scaling_configuration block. However I have changed to a normal RDS which has deployed sucessfully. However every time I run terraform plan/apply it keeps changing the serverlessv2_scaling_configuration block in the state file

Serverless:

resource "aws_rds_cluster" "default" {
  cluster_identifier              = "aurora-${var.environment}-${var.cluster_identifier}"
  db_subnet_group_name            = "private"
  engine                          = var.engine
  engine_version                  = var.engine_version
  availability_zones              = var.availability_zones
  database_name                   = var.cluster_identifier
  master_username                 = var.rds_master_username
  master_password                 = var.rds_master_password
  backup_retention_period         = var.backup_retention_period
  preferred_backup_window         = var.preferred_backup_window
  vpc_security_group_ids          = [var.security_group_names]
  storage_encrypted               = true
  skip_final_snapshot             = true
  deletion_protection             = true
  allow_major_version_upgrade     = var.allow_major_version_upgrade
  enabled_cloudwatch_logs_exports = var.enabled_cloudwatch_logs_exports
  serverlessv2_scaling_configuration {
    max_capacity =  0.5
    min_capacity =  4
  }
}

Current without serverlessv2_scaling_configuration block

resource "aws_rds_cluster" "default" {
  cluster_identifier              = "aurora-${var.environment}-${var.cluster_identifier}"
  db_subnet_group_name            = "private"
  engine                          = var.engine
  engine_version                  = var.engine_version
  availability_zones              = var.availability_zones
  database_name                   = var.cluster_identifier
  master_username                 = var.rds_master_username
  master_password                 = var.rds_master_password
  backup_retention_period         = var.backup_retention_period
  preferred_backup_window         = var.preferred_backup_window
  vpc_security_group_ids          = [var.security_group_names]
  storage_encrypted               = true
  skip_final_snapshot             = true
  deletion_protection             = true
  allow_major_version_upgrade     = var.allow_major_version_upgrade
  enabled_cloudwatch_logs_exports = var.enabled_cloudwatch_logs_exports
} 

Terrraform Plan output

  ~ resource "aws_rds_cluster" "default" {  
        id                                  = "aurora-development-mydb"
        # (41 unchanged attributes hidden)

      ~ serverlessv2_scaling_configuration {
          - max_capacity = 4 -> null
          - min_capacity = 0.5 -> null
        }
    }

Terraform state file snippet

            "scaling_configuration": [],
            "serverlessv2_scaling_configuration": [
              {
                "max_capacity": 4,
                "min_capacity": 0.5
              }
            ],
            "skip_final_snapshot": true,

How can I resolve this?

PS We using terraform cloud

Hi @isatfg,

I think you’ve found a bug in the AWS provider.

I see the following logic in the AWS provider for handling this update action:

It only sets requestUpdate = true if there’s at least one serverlessv2_scaling_configuration block in the configuration. If requestUpdate is false after it’s finished analyzing the configuration then it skips making any update at all, causing the change to be ignored.

I’ve not completed a full analysis here so I can’t be sure that I’m right about the cause of the bug, but I would still suggest opening a bug report in the AWS provider repository so that the AWS provider development team can review it. If you do open an issue, I would suggest linking to this comment so that the AWS provider team can see my initial theory and then either confirm or disprove it once they get into more detailed debugging.

Thanks!