Cloud SQL(PostgreSQL)のマシンタイプをTerraformで変更しようとしたところ、
次のようなエラーが出ていました。
Error: Error, failed to update instance settings for : googleapi: Error 400: Invalid request: Only custom or shared-core instance Billing Tier type allowed for PostgreSQL database., invalid
PostgreSQLの場合はカスタムもしくは共有コアマシンタイプのみの指定となっているようで、
このことはTerraformのドキュメントでも触れられていました。
Postgres supports only shared-core machine types, and custom machine types
共有コアとは要件が低いワークロード向けに用意されているマシンタイプで、現在 db-f1-micro
と db-g1-small
があります。
そのため、Terraformの google_sql_database_instance
リソースの tier
に指定できる文字列は db-f1-micro
か db-g1-small
かカスタムマシンタイプのみで、カスタムマシンタイプは次のように指定します。
db-custom-<CPU>-<RAM>
ただ次のような制約があります。
- vCPU
- 1または2~96の間の偶数
- メモリ
- vCPUあたり0.9~6.5GB
- 256MBの倍数
- 3.75GB(3840MB)以上
例えばマシンタイプ db-n1-standard-2
にしたい場合は
vCPU 2, メモリ 7.5GB
というスペックになりますので db-custom-2-7680
という指定の仕方になります。
resource "google_sql_database_instance" "postgres" {
...
settings {
tier = "db-n1-standard-2" # NG
tier = "db-custom-2-7680" # OK!
}
}
Discussion