为什么 terraform plan 会锁定状态?

Grz*_*zki 5 terraform

terraform planQ:默认锁定状态的操作有什么意义?

(我知道它可能会被禁用-lock=false

语境:

  • (据我了解)该plan操作不应该改变状态。
  • plan确实从某个版本refresh(通常会改变状态)开始,但即使是主动的标准输出也terraform plan表示计划启动的刷新并非如此:
    Refreshing Terraform state in-memory prior to plan...
    The refreshed state will be used to calculate this plan, but will not be
    persisted to local or remote state storage.
Run Code Online (Sandbox Code Playgroud)
  • 我在Hashicorp网站上看到了这个问题,似乎没有提供确凿的答案。

cen*_*cen 1

我相信这是因为它在幕后执行状态刷新:

-refresh=false - 在检查配置更改之前禁用将 Terraform 状态与远程对象同步的默认行为。

https://www.terraform.io/docs/cli/commands/plan.html

我能想到的另一个原因是,如果您运行一个计划并且有人已经锁定了状态,则意味着它正在对状态执行更改,因此读取状态可能会给您一个在释放锁后不再有效的计划

https://github.com/hashicorp/terraform/issues/28130