当 terraform 在中间失败时会发生什么? [英] What happens when terraform fails in middle?

查看:48
本文介绍了当 terraform 在中间失败时会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试执行 terraform 代码时,如果它在代码中间失败会发生什么?假设我们正在尝试将四个应用程序部署到一个 ubuntu 实例上.它完成了部署 2 个实例,并在第三个失败?它是停止整个过程并报告错误,还是跳过失败的部分并移动到下一个部分,即(在本例中为第四次部署)?请让我知道这件事.

while trying to execute terraform code, what happens if it fails in the middle of code? Lets say if we are trying to deploy four applications on to a ubuntu instance. It completed deploying 2 instances, and failed at third ? Does it stops the entire process and report the error or does it skips the part where it failed and moves to next part where i.e ( in this case 4th deployment) ? please let me know about this.

你也可以为 (ansible,puppet,chef) 提供上述相同的过程吗?

can you teel the above same process for (ansible,puppet,chef) also ?

感谢和问候.

推荐答案

在内部,Terraform 通过创建所有这些操作的图表来执行计划的操作,同时考虑到配置中指定的依赖关系,然后执行 并发 图遍历以适当的顺序访问所有这些操作.

Internally Terraform performs the planned actions by creating a graph of all of those actions, taking into account the dependencies specified in the configuration, and then performs a concurrent graph walk to visit all of those actions in a suitable order.

虽然这主要是实现细节,但我提到它是因为它会影响 Terraform 如何响应错误:如果任何操作失败,Terraform 将不会开始处理任何新操作它将完成任何其他操作可能已经在进行中的操作与失败的操作同时运行.

While that's mostly implementation detail, I mention it because it affects how Terraform responds to errors: if any of the actions fail, Terraform will not start working on any new actions but it will finish any other actions that might already be in progress that were running concurrently with the one that failed.

听起来你正在想象这样一个资源块的情况:

It sounds like you're imagining a situation with a resource block like this:

resource "aws_instance" "example" {
  count = 4

  # ...
}

Terraform 中的依赖关系是在资源而不是资源实例之间,因此 aws_instance.example 的四个不同实例(aws_instance.example[0]aws_instance.example[1] 等)通常会同时创建,因此如果创建 aws_instance.example[2] 失败,那么至少其他一些可能会也已经在创建过程中,因此 Terraform 将在失败之前等待这些完成.

Dependencies in Terraform are between resources rather than resource instances, and so the four different instances of aws_instance.example (aws_instance.example[0], aws_instance.example[1], etc) will typically be created all concurrently, and so if the creation of aws_instance.example[2] fails then it's likely that at least some of the others will already be in the process of creating too, and so Terraform will wait for those to complete before failing.

但是,一旦所有活动动作结束,Terraform 将不会开始任何新动作,而是会出现错误退出.特别是,不会开始任何依赖于任何 aws_instance.example 实例的操作.

However, once all active actions have concluded, Terraform will not start any new actions and will instead exit with an error. In particular, no actions which depend on any of the aws_instance.example instances will begin.

但是,Terraform 确实记住了应用操作后创建的状态快照中的部分状态,因此它会记住哪些对象成功,哪些没有.如果您再次运行 terraform apply,那么 Terraform 应该会看到一些实例尚不存在(或者,它们存在但被污染",具体取决于操作失败的具体程度),并计划特别创建或替换那些失败的实例,同时保持成功的实例不变.

However, Terraform does remember the partial state in the state snapshot created after the apply operation, so it will remember which of the objects succeeded and which didn't. If you run terraform apply again then Terraform should see that some of the instances don't exist yet (or, alternatively, that they exist but are "tainted", depending on how exactly the operation failed), and will plan to either create or replace those failed instances in particular, while leaving the successful ones unchanged.

我对你提到的其他软件不够熟悉,无法与其中的类似行为(如果有的话)进行比较.

I'm not familiar enough with the other software you mentioned to make a comparison with similar behaviors (if any) in those.

这篇关于当 terraform 在中间失败时会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆