Open1

Google Cloud の Memorystore で Valkey インスタンスの削除保護を消す方法

yuyake0084yuyake0084

前提

terraform でリソース定義をしている。
deletion_protection_enabled は容易に消せないように true で宣言している。

resource "google_memorystore_instance" "valkey" {
  instance_id                 = "hoge-valkey"
  location                    = "asia-northeast1"
  engine_version              = "VALKEY_8_0"
  mode                        = "CLUSTER"
  deletion_protection_enabled = true # ここのお話
  ...
}

削除しようとすると何が起きたか?

検証の為にコンソール上からポチポチで削除しようとした時に下記エラーが発生。
要約すると削除保護かけてるから消せないから削除保護を false に更新してね、というもの。

The cluster is deletion protected. Please disable deletion protection to delete the cluster. To disable, update DeleteProtectionEnabled to false via the Update API. Please follow https://cloud.google.com/memorystore/docs/cluster/deletion-protection#setting_or_removing_deletion_protection_on_an_existing_instance : failed precondition

terraform から false に更新して apply しても更新可能なのだろうが、諸事情により terraform による更新できずエラーで紹介されたリンクを基に gcloud コマンドでの更新を試みる。

しかしこのリンクの手法は(今回の例では)誤りだった

https://cloud.google.com/memorystore/docs/cluster/deletion-protection#setting_or_removing_deletion_protection_on_an_existing_instance

リンク内紹介されている削除保護を消すコマンドは下記である。

$ gcloud redis clusters update INSTANCE_ID \
  --no-deletion-protection

しかし、これをそのまま素直に実行すると、下記のようにエラーが発生する。

ERROR: (gcloud.redis.clusters.update) NOT_FOUND: Resource 'Valkeyのリソース名' was not found. This command is authenticated as '私のアカウント' which is the active account specified by the [core/account] property

それもそのはず。
このコマンドは Redis クラスターの削除保護を更新する為のものであり、Valkey インスタンスの削除保護を更新するものではないのだ。

では Valkey の削除保護を更新するには?

素直に Memorystore for Valkey の削除保護を更新する方法をググってみたら下記リンクに辿り着いた。

https://cloud.google.com/memorystore/docs/valkey/deletion-protection?hl=ja

記載されていた下記コマンドにて無事 Valkey の削除保護を false にできた。

$ gcloud beta memorystore instances update INSTANCE \
  --no-deletion-protection-enabled \
  --location=REGION_ID

最後にひとこと

Google Cloud の中の人、2025年5月時点では案内するリンク間違えてるから直して欲しいな!!!!