如何在不影响数据库资源 运行 的情况下升级 terraform 和提供程序版本?

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

将 terraform 和 aws 提供程序的版本从较低版本更改为较高版本后,此数据库资源将执行 create replacement and then destroy。即使数据库实例不会被销毁和重新创建,但它的相关选项组和参数组会被更新。 它会导致 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.

比如重启数据库实例。

通过查看您的 terraform 计划,它正在更改 db_option_groupaws_db_parameter_group 的描述是什么导致重新创建选项和资源组并就地更新数据库实例,替换选项组实例的资源和资源可能会导致短暂的中断,具体取决于正在更改的选项。

来自 modify-db-instance 手册:

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.

我的建议是在应用到关键数据库之前在非生产环境中测试该计划,或者如果没有任何其他选择,则不要更改资源描述。