【问题标题】:Terraform forget resource and recreate?Terraform 忘记资源并重新创建?
【发布时间】:2018-10-23 20:20:44
【问题描述】:

我是 terraform 的新手,并且已经玩了一段时间了。在我尝试执行的场景中,我尝试为我的每个部署创建一个堆栈。我能够创建我需要的资源。但是,当我想部署一个新堆栈时,它正试图破坏已经存在的堆栈。我曾尝试将生命周期密钥与防止销毁一起使用,但这会引发错误,指出无法删除资源。

the plan would destroy this resource, but it currently has lifecycle.prevent_destroy set to true. To avoid this error and continue with the plan, either disable lifecycle.prevent_destroy or adjust the scope of the plan using the -target flag.

有没有办法跳过或让 terraform “忘记”它创建的资源?我知道这很棘手,因为 terraform 维护的状态文件,但任何线索都会有所帮助。

提前致谢。

【问题讨论】:

  • 请安装您的 Terraform。
  • 如果您想保留多个已部署的 Terraform 堆栈,您应该使用单独的状态文件和/或工作区。
  • 用于独立检查工作区的不同部署 (terraform.io/docs/state/workspaces.html)。关于销毁:你想销毁和再利用什么样的资源?

标签: terraform


【解决方案1】:

您可以使用terraform state rm <resource> 从状态中删除资源,也许这就是您要查找的内容?

更多信息请访问https://www.terraform.io/docs/commands/state/rm.html

【讨论】:

    【解决方案2】:

    我认为您需要将 terraform 工作空间用于不同的部署(环境?)。所以你将能够为不同的环境创建不同的资源(这在评论Terraform forget resource and recreate?中有提到)

    信息:https://www.terraform.io/docs/state/workspaces.html

    【讨论】:

      猜你喜欢
      • 2022-07-24
      • 2018-09-24
      • 2022-12-29
      • 2020-11-23
      • 2019-03-12
      • 2021-08-28
      • 2023-03-20
      • 1970-01-01
      • 2020-08-31
      相关资源
      最近更新 更多