atmos icon indicating copy to clipboard operation
atmos copied to clipboard

`atmos terraform force-unlock` does not work

Open mss opened this issue 1 year ago • 6 comments

Describe the Bug

atmos terraform force-unlock worked before but probably only randomly and doesn't work at all anymore (I guess) since v1.100 which now always cleans the workspace. See below for an example.

I guess the proper solution would be to skip the workspace switch for force-unlock.

Expected Behavior

atmos terraform force-unlock should work.

Steps to Reproduce

  1. Configure an S3 backend with a DynamoDB database for locking.
  2. Start some atmos terraform $component --stack $stack apply but cancel it right in the middle by hitting via Ctrl+C twice.
  3. Try atmos terraform plan $component --stack $stack
  4. Try atmos terraform force-unlock $component --stack $stack $uuid where uuid is the value from the previous error.

Screenshots

# atmos terraform force-unlock wms-base --stack wms-xe02-sandbox 8ac7bbfc-c1b4-615d-38d7-f7ba634aa4bb --skip-init

Workspace "wms-xe02-sandbox-wms-base" doesn't exist.

You can create this workspace with the "new" subcommand 
or include the "-or-create" flag with the "select" subcommand.
failed to lock s3 state: operation error DynamoDB: PutItem, https response error StatusCode: 400, RequestID: GK00L3DNLAJF2N4KSMUCPHAMA3VV4KQNSO5AEMVJF66Q9ASUAAJG, ConditionalCheckFailedException: The conditional request failed
Lock Info:
  ID:        8ac7bbfc-c1b4-615d-38d7-f7ba634aa4bb
  Path:      sl-atmos-tfstate-123456789012/wms/xe02/sandbox/wms-xe02-sandbox-wms-base/terraform.tfstate
  Operation: OperationTypeApply
  Who:       stretz@slpn-nb-mss
  Version:   1.8.5
  Created:   2024-11-22 13:59:40.20546289 +0000 UTC
  Info:      

exit status 1

Environment

  • Version 1.105.0

Additional Context

No response

mss avatar Nov 22 '24 14:11 mss

@mss thank you for reporting this

aknysh avatar Nov 22 '24 14:11 aknysh

Just using the default workspace (via TF_WORKSPACE=default) doesn't work, results in the error Failed to unlock state: failed to retrieve lock info for lock ID "8ac7bbfc-c1b4-615d-38d7-f7ba634aa4bb": unexpected end of JSON input. From running the whole thing with TF_LOG=debug it looks like the LockID is wrong.

mss avatar Nov 25 '24 12:11 mss

This doesn't work either:

TF_WORKSPACE=default atmos terraform shell wms-base --stack wms-xe02-sandbox
unset TF_WORKSPACE
terraform workspace new -lock=false wms-xe02-sandbox-wms-base
terraform force-unlock 8ac7bbfc-c1b4-615d-38d7-f7ba634aa4bb

The terraform workspace new fails already. Looks like the -lock=false is ignored so there may be a terraform bug involved as well?

mss avatar Nov 25 '24 12:11 mss

Hi @mss We are tracking this bug and will look into it. Can not promise an ETA though

GabisCampana avatar Nov 26 '24 14:11 GabisCampana

I think this is at least partially broken on the Terraform side, cf. linked ticket.

mss avatar Nov 26 '24 14:11 mss

@aknysh FYI

GabisCampana avatar Nov 26 '24 17:11 GabisCampana