Terraform plan shows drift on genesyscloud_routing_queue due to state lock

Running into a weird issue with the Genesys Cloud Terraform provider. I have a script that updates queue settings nightly. Tonight it failed with a state lock error, but the lock file seems stuck.

Here is the error:

Error: Error acquiring the state lock
Reason: another process has a lock on the state
Lock Info:
 ID: abc-123-def
 Path: tfstate.lock
 Operation: OperationTypeUpdate
 Who: user@host
 Version: 1.0.0
 Created: 2023-10-27 10:00:00 +0000 UTC
 Info: 

I tried terraform force-unlock abc-123-def but it says the lock ID doesn’t match. The state file is stored in S3 with DynamoDB for locking. The DynamoDB table shows the lock exists, but the process ID is dead.

When I run terraform plan now, it shows massive drift on genesyscloud_routing_queue. It thinks every setting has changed. I checked the API directly using the REST proxy in a to verify the actual config. The values match the terraform state before the crash.

Is there a way to clear the lock without losing state? Or do I need to manually edit the state file? I don’t want to break the queue config. The terraform docs mention force-unlock but it’s not working. Any ideas?

State locks in Terraform often persist if the process handling the update crashes or loses connection before releasing it. This is common with nightly scripts that might get terminated by idle timeouts or resource constraints. Since you’re seeing a stale lock from user@host, the previous run likely didn’t complete its cleanup routine.

You can safely force-remove the lock if you’re certain no other process is actively writing to that state. Run this command to bypass the lock:

terraform force-unlock abc-123-def

Replace abc-123-def with the actual Lock ID from your error log. After removing the lock, verify the state is clean by running a terraform plan. If the provider still shows unexpected drift, check if your nightly script is modifying attributes that are also managed manually in the UI, which causes constant reconciliation loops. Make sure your script runs with consistent environment variables to avoid accidental state corruption.