Fixing Terraform ‘Error acquiring state lock’ in Azure

When Terraform runs, it locks the state file so it cannot be modified by other processes.

If a Terraform run ends unexpectedly (crashes or is canceled mid-run), or there have been multiple pipelines running at the same time that use the same state file, then the state file remains locked. On the next run, you may see any error as pictured below showing that the ‘state blob is already locked’.

Error message: State blob is already locked