【问题标题】:GCP Cloud SQL failed to delete instance because `deletion_protection` is set to true - gcloud toggle?GCP Cloud SQL 无法删除实例,因为“deletion_protection”设置为 true - gcloud 切换?
【发布时间】:2021-03-13 19:08:35
【问题描述】:

错误信息:

地形破坏

module.application.google_sql_database_instance.sql-db-xxx:正在销毁... [id=db-xxx]

错误:错误,删除实例失败,因为删除保护设置为真。将其设置为 false 以继续删除实例

terraform 解决方案在这里:

https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance

在较新版本的提供程序上,您必须显式设置 delete_protection=false(并运行 terraform >apply 将字段写入状态)才能销毁实例。建议在您准备好销毁实例及其数据库之前不要设置此 >field(或将其设置为 true)。

问题:

我不想更改 terraform 脚本。我宁愿通过 gcloud 切换删除保护标志,然后照常销毁。 对于 gcloud 虚拟机,我可以切换一个删除保护标志。但是,我找不到数据库的相应标志:

cloud sql instances describe db-xxx

  • 这个删除保护标志元数据是否在 terraform 本身内?

  • 如果不是,切换它的 gcloud 命令是什么?

  • 如果是这样,我如何在不修改代码的情况下通过 terraform 覆盖它;即命令行参数?

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

【问题讨论】:

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


    【解决方案1】:

    回答您的问题:

    1. 来自 Terraform 文档:

    deletion_protection - 是否允许 Terraform 销毁实例。

    所以是的,这在 Terraform 本身内。 GCP 上的删除保护标志目前仅适用于 Compute Engine 实例,不适用于 Cloud SQL 实例。

    1. 目前,只能在 Compute Engine 实例上切换删除保护。

    2. 您可以考虑像这样使用input variables

    terraform apply -var="deletion_protection=false"
    terraform destroy
    

    还有其他使用输入变量的方法。如需更多参考,请查看link

    【讨论】:

    • 我使用 bigquery,并且从今天开始在表上看到 delete_protection = false(ish)
    猜你喜欢
    • 2021-02-13
    • 1970-01-01
    • 2022-07-26
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-02
    • 2021-04-23
    相关资源
    最近更新 更多