AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1012436
Accepted
Anthony Kong
Anthony Kong
Asked: 2020-04-16 06:05:50 +0800 CST2020-04-16 06:05:50 +0800 CST 2020-04-16 06:05:50 +0800 CST

在应用 terraform 计划期间,如何在网络问题后清除 terraform 资源?

  • 772

我已经应用了一个 terraform 来创建一个 redis 集群。

进行到一半时,应用程序进程失败并显示以下错误消息:

Error: Error waiting for elasticache replication group (my-project) to be created: SerializationError: failed decoding Query response
    status code: 200, request id: 3d5a5394-20f0-4834-9e2a-9aff20cceecf
caused by: read tcp 192.168.86.116:53912->54.222.5.156:443: read: connection reset by peer

我知道我已经成功创建了集群,因为我可以使用redis-cli.

但是,如果我再做terraform apply一次,terraform 会说

module.my_project.aws_elasticache_replication_group.main[0] is tainted, so must be replaced

它试图破坏和重新创建资源,而不是no action像我预期的那样。

我已尝试将资源导入状态文件以纠正问题。但是 terraform 会引发错误:

错误:资源已由 Terraform 管理

如果操作一开始就成功,我将看不到tainted错误消息。

有什么办法可以从这个问题中恢复过来?我想避免删除然后重新创建资源。

理想情况下,我希望我可以清除状态文件中的资源,这样 terraform 就不会尝试破坏新创建的集群。

terraform redis
  • 2 2 个回答
  • 3731 Views

2 个回答

  • Voted
  1. Best Answer
    Martin Atkins
    2020-04-16T16:14:45+08:002020-04-16T16:14:45+08:00

    Terraform 将对象标记为已污染,因为由于错误,无法确定该对象是否处于完全功能状态。

    但是,如果您知道(通过带外检查)对象处于合适的状态,则可以使用以下terraform untaint命令覆盖 Terraform 的确定:

    terraform untaint module.my_project.aws_elasticache_replication_group.main[0]
    

    在此之后,Terraform 将认为该对象处于适合进一步操作的状态。理想情况下,这将意味着后续程序terraform plan根本不会检测到该实例的任何更改。如果创建不完整但可以通过更新进行修复,则提供者可能会生成就地更新以匹配配置的计划。

    • 4
  2. Anthony Kong
    2020-04-16T06:27:03+08:002020-04-16T06:27:03+08:00

    我可以先从状态文件中删除资源,然后再次导入。

    1. 拆除

    terraform state rm -state=<state-file> "module.my_project.aws_elasticache_replication_group.main[0]"
    

    2. 进口

    terraform import -state=<state-file> "module.my_project.aws_elasticache_replication_group.main[0]" <resource-id>
    
    • 1

相关问题

  • 使用 Terraform 创建 GCE 实例,附加辅助磁盘时出错?

  • Terraform,在污点上出现“模块根目录没有资源”错误

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve