Grzegorz Oledzki
Grzegorz Oledzki

Reputation: 24281

Why does terraform plan lock the state?

Q: What's the point for the terraform plan operation to lock the state by default?

(I know it might be disabled with -lock=false)

Context:

    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.

Upvotes: 5

Views: 2802

Answers (1)

cen
cen

Reputation: 2943

I believe it is because behind the scenes it performs a state refresh:

-refresh=false - Disables the default behavior of synchronizing the Terraform state with remote objects before checking for configuration changes.

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

The other reason I can think of is that if you run a plan and someone already locked the state, it means it is performing changes to the state so reading the state might give you a plan that is no longer valid after the lock is freed

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

Upvotes: 1

Related Questions