It might be possible that you are in the middle of running terraform plan
or terraform apply
command but unfortunately, you ended up with the error - Error locking state: Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed.
Reason- Terraform has an internal validation that checks if there is a state lock already present then another process can not access the same resource with the same state
- Terraform allows you to have one process with one state lock.
- When more than one process tries to acquire the same state lock on the same resource then it might result in the Error locking state: Error acquiring the state lock: ConditionalCheckFailedException.
- Another possible reason is the
- Network outage - Because of the network outage there is a chance the previous terraform process might have terminated before it completion resulting in the error.
- incorrect AWS profile - In your project, you have multiple AWS profile but you are using an incorrect AWS profile which will also result in the same error.
How to fix it?
1) Kill task by id terraform force-unlock -force {ID error task}
2) Use -lock=false along with terraform plan - If the previous force-unlock command does not work then use the -lock=false command
3) kill terraform process- Well if none of the previous solutions works then I would recommend using kill -9
to terminate the process.
- Find the terraform Process ID using the command
ps aux | grep terraform
- Kill the process using -
kill -9 <process_id>