gpt4 book ai didi

terraform - 避免破坏之前创建的资源

转载 作者:行者123 更新时间:2023-12-03 23:23:12 25 4
gpt4 key购买 nike

我想避免 terraform 破坏我之前创建的资源,而是创建新的资源。

我/想要像这样使用 terraform:

  • 创建 AWS IAM 组和策略
  • 将用户附加到这些组
  • 我想通过提供外部 var 文件来创建新的组和用户,就像我为上述用户和组所做的那样

  • 但是当我尝试传递新的 var 文件时,我创建了新资源并删除了前一个资源,所以我想创建新资源但仍想保留旧资源,直到我提到我想删除它。

    这对我来说真的很困惑,有人可以指出我如何实现它吗?

    提前致谢

    最佳答案

    Advance terraform state management 很棘手,所以要小心。我已经成功销毁了其他资源,同时保留了一些资源。

    Usage: terraform state rm [options] ADDRESS...

    The command will remove all the items matched by the addresses given.

    Items removed from the Terraform state are not physically destroyed. Items removed from the Terraform state are only no longer managed by Terraform. For example, if you remove an AWS instance from the state, the AWS instance will continue running, but terraform plan will no longer see that instance.

    There are various use cases for removing items from a Terraform state file. The most common is refactoring a configuration to no longer manage that resource (perhaps moving it to another Terraform configuration/state).

    The state will only be saved on successful removal of all addresses. If any specific address errors for any reason (such as a syntax error), the state will not be modified at all.

    This command will output a backup copy of the state prior to saving any changes. The backup cannot be disabled. Due to the destructive nature of this command, backups are required.

    terraform state rm resource_to_stay terraform plan -destroy <- 将对销毁进行“试运行”,确保资源不存在 terraform destroy terraform import resource_to_stay terraform plan <- 这应该有导入资源的输出,确保它不会被删除,也就是显示为红色。 terraform apply

    关于terraform - 避免破坏之前创建的资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36403998/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com