How to upgrade terraform and provider version without affect db resource's running?

Viewed 299

After changing terraform and aws provider's version from a lower one to a higher one, this db resource will execute create replacement and then destroy. Even the db instance won't be destroyed and recreate, but its related option group and parameter group will be updated. Will it cause some issue for the running DB service in AWS?

+ create
~ update in-place
+/- create replacement and then destroy

Terraform will perform the following actions:

  # module.db.module.db_instance.aws_db_instance.this[0] will be updated in-place
~ resource "aws_db_instance" "this" {
        id                    = "svc-mysql"
        name                  = "svc"
      ~ option_group_name     = "svc-mysql-20190238920200000000" -> (known after apply)
      ~ parameter_group_name  = "svc-mysql" -> (known after apply)
      ~ skip_final_snapshot   = true -> false
  ...

  # module.db.module.db_instance.random_id.snapshot_identifier[0] will be created
+ resource "random_id" "snapshot_identifier" {
  ...

  # module.db.module.db_option_group.aws_db_option_group.this[0] must be replaced
+/- resource "aws_db_option_group" "this" {
      ~ arn                      = "arn:aws:rds:us-east-2:19312071070:og:svc-mysql-20190238920200000000" -> (known after apply)
      ~ id                       = "svc-mysql-20190238920200000000" -> (known after apply)
      ~ name                     = "svc-mysql-20190238920200000000" -> (known after apply)
      ~ option_group_description = "Option group for svc-mysql" -> "svc-mysql option group" # forces replacement
  ...

  # module.db.module.db_parameter_group.aws_db_parameter_group.this[0] must be replaced
+/- resource "aws_db_parameter_group" "this" {
      ~ arn         = "arn:aws:rds:us-east-2:19312071070:pg:svc-mysql-20190238920200000000" -> (known after apply)
      ~ description = "Database parameter group for svc-mysql" -> "svc-mysql parameter group" # forces replacement
      ~ id          = "svc-mysql-20190238920200000000" -> (known after apply)
      ~ name        = "svc-mysql-20190238920200000000" -> (known after apply)
  ...

  # module.db.module.db_subnet_group.aws_db_subnet_group.this[0] will be updated in-place
~ resource "aws_db_subnet_group" "this" {
    ~ description = "Database subnet group for svc-mysql" -> "svc-mysql subnet group"
  ...

Plan: 3 to add, 2 to change, 2 to destroy.

Such as restart db instance.

1 Answers

By looking on your terraform plan, it's changing the description for db_option_group and aws_db_parameter_group what's causing option & resource groups to be re-created and db instance updated in-place, replacing option groups and resources for the instance can cause a brief outage, depending on the options being changes.

From the modify-db-instance manual:

Changing this parameter doesn't result in an outage except in the following case and the change is applied during the next maintenance window unless the ApplyImmediately parameter is enabled for this request. If the parameter change results in an option group that enables OEM, this change can cause a brief (sub-second) period during which new connections are rejected but existing connections are not interrupted.

My recommendation is to test the plan in non-production environment before applying to crucial databases, alternatively just don't change resources descriptions if don't have any other options.

Related