nerdexam
HashiCorp

TA-002-P · Question #391

Your configuration file has been locked accidentally. What of the following command would you use to unlock?

The correct answer is C. terraform force-unlock. terraform force-unlock is the correct command to manually release a locked Terraform state file when the lock was not automatically released after an interrupted operation.

Implement and maintain state

Question

Your configuration file has been locked accidentally. What of the following command would you use to unlock?

Options

  • Aterraform filename-unlock
  • Bdelete the file and create a new state file
  • Cterraform force-unlock
  • Dstate.tf-unlock

How the community answered

(27 responses)
  • B
    4% (1)
  • C
    93% (25)
  • D
    4% (1)

Why each option

terraform force-unlock is the correct command to manually release a locked Terraform state file when the lock was not automatically released after an interrupted operation.

Aterraform filename-unlock

'terraform filename-unlock' is not a valid Terraform CLI command and does not exist in the Terraform command set.

Bdelete the file and create a new state file

Deleting the state file and creating a new one would destroy all tracked resource state, leading to data loss and infrastructure drift - it is not the correct remediation for a lock issue.

Cterraform force-unlockCorrect

The 'terraform force-unlock' command removes the lock on a Terraform state by accepting the lock ID as an argument, preventing accidental unlocking of another operator's running state. It is the official Terraform CLI mechanism for resolving stale locks and should be used only when certain no other operation is in progress.

Dstate.tf-unlock

'state.tf-unlock' is not a valid Terraform CLI command or file-based operation for releasing a state lock.

Concept tested: Terraform state lock management with force-unlock

Source: https://developer.hashicorp.com/terraform/cli/commands/force-unlock

Topics

#Terraform state management#State locking#Terraform CLI commands#terraform force-unlock

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice