【问题标题】:How to set timeout for terraform apply?如何为 terraform 应用设置超时?
【发布时间】:2022-03-28 18:46:28
【问题描述】:

当我将 terraform apply 应用于某些 tf.我想设置超时而不是永远持续下去。

谢谢

几个例子 - https://github.com/hashicorp/terraform/issues/16458 https://github.com/terraform-providers/terraform-provider-aws/issues/2068

但他们都专注于具体的解决方案。我不想要无限循环,无论出于何种原因,我只想要一个应用标志,它会在特定时间后停止尝试。我正在考虑一个外部命令来杀死它,但我想在实施之前看看是否有实际的 terraform 解决方案。

【问题讨论】:

  • 你能提供一个minimal reproducible example 和可能的输出吗?没有通用的方法来超时事情或整个操作,但一些资源在创建/更新/销毁时设置了可配置的超时。达到此超时时,您是否希望发生特定的事情?

标签: terraform


【解决方案1】:

如今,Terraform SDK 具有用于资源超时的特殊字段。官方文档here.

例如,可以在资源描述中为某些操作添加超时:

resource "yandex_mdb_postgresql_cluster" "my-cluster-name" {
  ...
  timeouts {
    create: "1h30m",
    update: "2h",
    delete: "20m"
  }
}

【讨论】:

    【解决方案2】:

    截至this issue,目前还没有terraform直接提供的解决方案。

    您可以使用 Linux 的 timeout 命令实现此行为。

    例如:

    $ timeout 1h terraform apply
    

    此示例将在一小时后将SIGTERM 信号发送到 terraform。

    有关此命令的更多信息,请参阅this reference

    【讨论】:

    • terraform 应该在 SIGTERM 上启动正常停止,以等待正在进行的操作完成。否则它将保持在中间状态。等待时间可以通过 timeouts 参数配置。
    猜你喜欢
    • 2021-03-28
    • 2016-06-29
    • 1970-01-01
    • 2011-10-29
    • 2021-12-20
    • 2017-04-29
    • 2018-07-08
    • 2010-11-04
    • 1970-01-01
    相关资源
    最近更新 更多