gcloud - GCP Cloud SQL 未能删除实例,因为 `deletion_protection` 设置为 true - gcloud 切换?

标签 gcloud google-cloud-sql terraform-provider-gcp

错误信息:

terraform destroy

module.application.google_sql_database_instance.sql-db-xxx: Destroying... [id=db-xxx]

Error: Error, failed to delete instance because deletion_protection is set to true. Set it to false to proceed with instance deletion


terraform 解决方案在这里:
https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance

On newer versions of the provider, you must explicitly set deletion_protection=false (and run terraform >apply to write the field to state) in order to destroy an instance. It is recommended to not set this >field (or set it to true) until you're ready to destroy the instance and its databases.


题:
我不想对 terraform 脚本进行更改。我宁愿通过 gcloud 切换删除保护标志,然后照常销毁。
对于 gcloud 虚拟机,我可以切换一个删除保护标志。但是,我找不到数据库的相应标志:cloud sql instances describe db-xxx
  • 这是 terraform 本身中的删除保护标志元数据吗?
  • 如果没有,切换它的 gcloud 命令是什么?
  • 如果是这样,如何在不修改代码的情况下通过 terraform 覆盖它;即命令行参数?

  • 我没有足够的“积分”可以添加到类似标题的现有线程中。

    最佳答案

    回答您的问题:

  • 来自 Terraform 文档:

  • deletion_protection - Whether or not to allow Terraform to destroy the instance.


    所以是的,这是在 Terraform 内部。 GCP 上的删除保护标志目前仅适用于 Compute Engine 实例,不适用于 Cloud SQL 实例。
  • 目前,只能在 Compute Engine 实例上切换删除保护。
  • 您可以考虑使用 input variables像这样:
  • terraform apply -var="deletion_protection=false"
    terraform destroy
    
    还有其他方法可以使用输入变量。如需更多引用,请访问 link .

    关于gcloud - GCP Cloud SQL 未能删除实例,因为 `deletion_protection` 设置为 true - gcloud 切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65097668/

    相关文章:

    google-cloud-platform - 如何使用特定服务帐户在 Dataproc 集群上提交作业?

    google-cloud-platform - gcloud compute ssh 停止

    google-cloud-platform - gsutil 重命名从不同目录复制的文件

    Terraform - 迭代嵌套 map

    google-cloud-platform - 我可以为 Terraform for GCP 授予管理员角色吗? (Cloud Run 域映射示例)

    kubernetes - 尽管启用了自动缩放,节点池不会将其节点大小减少到零

    google-cloud-sql - 谷歌云 SQL 导入 - HTTPError 403 : Insufficient Permission

    google-app-engine - 从已部署的应用连接到 Google Cloud SQL 服务器时遇到问题

    java - 使用 jdbc 驱动程序连接到 Cloud SQL 时出错

    google-cloud-platform - 无法创建 Cloud Composer