Aws_db_subnet_group name change should recreate database

Hello,

I’ve cloned the RDS learning example:

After successfully applying the code, the name of the db_subnet_group get’s changed.

resource "aws_db_subnet_group" "education" {
  name       = "helloeducation"
  subnet_ids = module.vpc.public_subnets

  tags = {
    Name = "Education"
  }
}

The terraform plan shows that the db_subnet_group has to be recreated.

Terraform will perform the following actions:

  # aws_db_instance.education will be updated in-place
  ~ resource "aws_db_instance" "education" {
      ~ db_subnet_group_name                  = "education" -> "helloeducation"
        id                                    = "education"
        name                                  = ""
        tags                                  = {}
        # (49 unchanged attributes hidden)
    }

  # aws_db_subnet_group.education must be replaced
-/+ resource "aws_db_subnet_group" "education" {
      ~ arn         = "arn:aws:rds:eu-west-1:394197307369:subgrp:education" -> (known after apply)
      ~ id          = "education" -> (known after apply)
      ~ name        = "education" -> "helloeducation" # forces replacement
      + name_prefix = (known after apply)
        tags        = {
            "Name" = "Education"
        }
        # (2 unchanged attributes hidden)
    }

Plan: 1 to add, 1 to change, 1 to destroy.


Howerver terraform apply notices that the RDS database is still using this db_subnet_group, so it cannot be recreated.


aws_db_subnet_group.education: Destroying... [id=education]

Error: InvalidDBSubnetGroupStateFault: Cannot delete the subnet group 'education' because at least one database instance: education ill using it.
        status code: 400, request id: caxxxxxxxxxxxxxxxfb7a6



Therefore I’d expect that terraform would also include recreation of the RDS, no?

As per my understanding the parameter should also be flagged with ForceNew: True in

Thanks&Best

Hm, I’ve built a custom provider using ForceNew: True. Indeed it would recreate the database however it also turns out that there are valid cases changing the db_subnet_group (VPC-A → VPC-B). However it’s not allowed to just change the name.

It would also require use of lifecycle rule create_before_destroy.