如何使用 Terraform 自动切换到 AWS 的 RDS 中的新参数组?

Posted

技术标签:

【中文标题】如何使用 Terraform 自动切换到 AWS 的 RDS 中的新参数组?【英文标题】:How to automatic switch to new parameter group in AWS' RDS with Terraform? 【发布时间】:2021-08-08 10:02:11 【问题描述】:

为RDS设置一个新的参数组,其方案是

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
~ update in-place
- destroy

Terraform will perform the following actions:

  # aws_db_parameter_group.this will be destroyed
- resource "aws_db_parameter_group" "this" 
      - arn         = "arn:aws:rds:us-east-1:12301923210921:pg:db-aurora-parameter-group" -> null
      - description = "Parameter group for db Aurora Postgres instance" -> null
      - family      = "aurora-postgresql12" -> null
      - id          = "db-aurora-parameter-group" -> null
      - name        = "db-aurora-parameter-group" -> null
      - tags        = 
          - "Application" = "myapp db"
          - "Project"     = "myproj"
          - "Terraform"   = "true"
         -> null
    

  # aws_rds_cluster.this will be updated in-place
~ resource "aws_rds_cluster" "this" 
      ~ db_cluster_parameter_group_name     = "db-aurora-cluster-parameter-group" -> (known after apply)
        id                                  = "db"
        tags                                = 
            "Application" = "myapp db"
            "Project"     = "myproj"
            "Terraform"   = "true"
        
        # (31 unchanged attributes hidden)
    

  # aws_rds_cluster_instance.this will be updated in-place
~ resource "aws_rds_cluster_instance" "this" 
      ~ db_parameter_group_name         = "db-aurora-parameter-group" -> (known after apply)
        id                              = "instance001"
        tags                            = 
            "Application" = "myapp db"
            "Project"     = "myproj"
            "Terraform"   = "true"
        
        # (25 unchanged attributes hidden)
    

  # aws_rds_cluster_parameter_group.this will be destroyed
- resource "aws_rds_cluster_parameter_group" "this" 
      - arn         = "arn:aws:rds:us-east-1:12301923210921:cluster-pg:db-aurora-cluster-parameter-group" -> null
      - description = "Cluster parameter group for db Aurora Postgres instance" -> null
      - family      = "aurora-postgresql12" -> null
      - id          = "db-aurora-cluster-parameter-group" -> null
      - name        = "db-aurora-cluster-parameter-group" -> null
      - tags        = 
          - "Application" = "myapp db"
          - "Project"     = "myproj"
          - "Terraform"   = "true"
         -> null

      - parameter 
          - apply_method = "immediate" -> null
          - name         = "log_lock_waits" -> null
          - value        = "1" -> null
        
      - parameter 
          - apply_method = "immediate" -> null
          - name         = "log_temp_files" -> null
          - value        = "0" -> null
        
      - parameter 
          - apply_method = "immediate" -> null
          - name         = "pgaudit.log_catalog" -> null
          - value        = "0" -> null
        
    

  # module.aws_db_parameter_group.aws_db_parameter_group.this will be created
+ resource "aws_db_parameter_group" "this" 
      + arn         = (known after apply)
      + description = "Parameter group for db Aurora Postgres instance"
      + family      = "aurora-postgresql12"
      + id          = (known after apply)
      + name        = (known after apply)
      + name_prefix = "db-"
      + tags        = 
          + "Application" = "myapp db"
          + "Name"        = "db"
          + "Project"     = "myproj"
          + "Terraform"   = "true"
        
    

  # module.aws_db_parameter_group.aws_rds_cluster_parameter_group.this will be created
+ resource "aws_rds_cluster_parameter_group" "this" 
      + arn         = (known after apply)
      + description = "Cluster parameter group for db Aurora Postgres instance"
      + family      = "aurora-postgresql12"
      + id          = (known after apply)
      + name        = (known after apply)
      + name_prefix = "db-"
      + tags        = 
          + "Application" = "myapp db"
          + "Name"        = "db"
          + "Project"     = "myproj"
          + "Terraform"   = "true"
        

      + parameter 
          + apply_method = "immediate"
          + name         = "log_lock_waits"
          + value        = "1"
        
      + parameter 
          + apply_method = "immediate"
          + name         = "log_temp_files"
          + value        = "0"
        
      + parameter 
          + apply_method = "pending-reboot"
          + name         = "pgaudit.log_catalog"
          + value        = "0"
        
    

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

通过 terraform 应用后,它会删除旧的参数组,但由于 AWS 规则不能。 如果手动切换到AWS中的新组,是可以的。

有没有办法使用 terraform 进行自动化?如果以后想添加新的参数组,最佳做法是什么?

【问题讨论】:

【参考方案1】:

这是一个长期存在但 TF 尚未解决的问题,已在 GitHub 上报告:

Modify aws_db_instance and delete aws_db_parameter_group breaks

你现在必须手动完成。

【讨论】:

根据我的经验,您需要自己向 AWS 提供商 PR 任何所需的更改。不是重大失误的问题。

以上是关于如何使用 Terraform 自动切换到 AWS 的 RDS 中的新参数组?的主要内容,如果未能解决你的问题,请参考以下文章

Terraform 中的 ECS 服务如何连接到 AWS 自动缩放组

您可以将 AWS Multi-Attach EBS 卷挂载到 Terraform 中的自动扩展组吗?

在 AWS CodeDeploy 中使用蓝/绿部署时,我们如何维护自动缩放组的状态?

使用 terraform 自动扩展 AWS spotfleet 会重置目标容量

在Terraform中为价格配置AWS自动扩展组?

如何自动切换角色策略(Terraform)