2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

TerraformでAurora serverlessV2を構築

Posted at

前提

required_providersで指定するhashicorp/awsのバージョンは4.15以上でないとserverlessv2_scaling_configurationが使用できないので注意

AuroraServerlessV2を構築

参考:https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster#rds-serverless-v2-cluster

従来のAuroraを構築するコードに下記の指定を追加する。

  • engine_modeprovisionedで追加
  • serverlessv2_scaling_configurationを追加
    引数は serverlessv2_scaling_configurationを参考にする
  • aws_rds_cluster_instanceinstance_classdb.serverlessで指定する

resource "aws_rds_cluster" "example" {
  cluster_identifier = "example"
  engine             = "aurora-postgresql"
  engine_mode        = "provisioned"
  engine_version     = "13.6"
  database_name      = "test"
  master_username    = "test"
  master_password    = "must_be_eight_characters"

  serverlessv2_scaling_configuration {
    max_capacity = 1.0
    min_capacity = 0.5
  }
}
 
resource "aws_rds_cluster_instance" "example" {
  cluster_identifier = aws_rds_cluster.example.id
  instance_class     = "db.serverless"
  engine             = aws_rds_cluster.example.engine
  engine_version     = aws_rds_cluster.example.engine_version
}

serverlessv2_scaling_configuration

参考:https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster#serverlessv2_scaling_configuration-argument-reference

引数は下記の2つで指定する。

max_capacity
(必須) プロビジョニングされた DB エンジン モードでの Aurora DB クラスターの最大容量です。最大容量は最小容量以上である必要があります。有効な容量値は0.5から128までの範囲で、0.5刻みで指定します。

min_capacity
(必須) プロビジョニングされたDBエンジンモードでのAurora DBクラスターの最小容量です。最小容量は最大容量以下である必要があります。有効な容量値は0.5から128の範囲で、0.5刻みで指定します。

 resource "aws_rds_cluster" "example" {
   # ... other configuration ...
 
   serverlessv2_scaling_configuration {
     max_capacity = 128.0
     min_capacity = 0.5
   }
 }

まとめ

既存でAurora構築のコードがある場合は殆どの設定を流用できました。
マルチAZについては別途対応が必要になりますので、記事を纏めれたらと思います。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?