unlock terraform states in aws dynamodb / yandex ydb

assuming Yandex Cloud

Here is an example for unlocking env/some-guest.

Configure AWS CLI (for Yandex Cloud) and use access key from same service account as used in ci/cd.

Generate keys: https://yandex.cloud/en/docs/iam/concepts/users/service-accounts#sa-key https://yandex.cloud/en/docs/iam/operations/sa/create-access-key

Find your “Document API endpoint” in “Managed Service for YDB / Databases” and tune your env

cp -pi ~/.bashrc ~/.bashrc.dist
vi ~/.bashrc

alias ydb='aws dynamodb --endpoint https://docapi.serverless.yandexcloud.net/ru-central1/b1gh6h9pmqiv7ju69f8n/etn278rqh2pmcbf9034c'

source ~/.bashrc

Check the table name

ydb list-tables
ydb describe-table --table-name tf_lock

Local backup and search for your lock item

mv -f tf_lock_scan.ydb tf_lock_scan.ydb.old.`date +%s`
ydb scan --table-name tf_lock > tf_lock_scan.ydb
less tf_lock_scan.ydb # /search_pattern

Check you have the right primary key

ydb get-item --table-name tf_lock --key '{ "LockID": { "S": "ke-tf-states/environments/prod/vm/diy-alerts/terraform.tfstate" } }'

Delete the lock

ydb delete-item --table-name tf_lock --key '{ "LockID": { "S": "ke-tf-states/environments/prod/vm/diy-alerts/terraform.tfstate" } }'

and check again with get-item (should be gone).


https://yandex.cloud/en/docs/ydb/concepts/dynamodb-tables


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun