TA-002-P · Question #420
Which are forbidden actions when the Terraform state file is locked? (Choose three.)
The correct answer is A. terraform destroy D. terraform apply E. terraform plan. When a Terraform state file is locked, commands that modify the state file or require a consistent view of the state to plan changes are forbidden to prevent data corruption.
Question
Which are forbidden actions when the Terraform state file is locked? (Choose three.)
Options
- Aterraform destroy
- Bterraform fmt
- Cterraform state list
- Dterraform apply
- Eterraform plan
- Fterraform validate
How the community answered
(55 responses)- A91% (50)
- B2% (1)
- C2% (1)
- F5% (3)
Why each option
When a Terraform state file is locked, commands that modify the state file or require a consistent view of the state to plan changes are forbidden to prevent data corruption.
terraform destroy attempts to delete infrastructure, which modifies the state file by removing resources, and is therefore forbidden during a lock.
terraform fmt only formats the configuration files and does not interact with the state file, so it is allowed when the state is locked.
terraform state list only reads the current state to display resources and does not modify it, making it permissible during a state lock.
terraform apply attempts to create, update, or delete infrastructure, directly modifying the state file to reflect changes, and is consequently forbidden during a lock.
terraform plan needs to read the current state to determine proposed changes and generate an execution plan; this is blocked if the state is locked to ensure the plan is based on an uncorrupted state.
terraform validate checks configuration syntax and semantics without interacting with the state file, so it can be performed when the state is locked.
Concept tested: Terraform state locking behavior
Source: https://developer.hashicorp.com/terraform/language/state/locking
Topics
Community Discussion
No community discussion yet for this question.