Skip to content

Commit

Permalink
address missing ddb table
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Oct 10, 2025
1 parent 9443488 commit 863fec2
Showing 1 changed file with 44 additions and 19 deletions.
63 changes: 44 additions & 19 deletions local-app/bin/manage-remote-state.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

VERSION="1.1.0"
VERSION="1.2.0"
THIS=$(basename $0 .sh)

test -r /apps/terraform/etc/aws-functions.sh && source /apps/terraform/etc/aws-functions.sh
Expand Down Expand Up @@ -59,19 +59,29 @@ then
echo "* syncing bucket s3://$bucket/ to $TFA"
aws --profile $(get_profile) --region $region s3 sync s3://$bucket/ ./$TFA/

echo "* archiving ddb table $ddbtable"
aws --profile $(get_profile) --region $region dynamodb scan --table $ddbtable > ./$TFA/$ddbtable.json
echo ""
if [ ! -z "$ddbtable" ]
then
echo "* archiving ddb table $ddbtable"
aws --profile $(get_profile) --region $region dynamodb scan --table $ddbtable > ./$TFA/$ddbtable.json
echo ""
else
echo "* no ddb table defined"
fi
fi

if [[ $ACTION == "list" ]] || [[ $ACTION == "delete" ]]
then
echo "* listing bucket s3://$bucket/$bucket_key"
aws --profile $(get_profile) --region $region s3 ls s3://$bucket/$bucket_key

echo "* listing ddb table entry $ddbentry"
aws --profile $(get_profile) --region $region dynamodb get-item --table $ddbtable --key "{\"LockID\":{\"S\":\"$ddbentry\"}}"
echo ""
if [ ! -z "$ddbtable" ]
then
echo "* listing ddb table entry $ddbentry"
aws --profile $(get_profile) --region $region dynamodb get-item --table $ddbtable --key "{\"LockID\":{\"S\":\"$ddbentry\"}}"
echo ""
else
echo "* no ddb table defined"
fi
fi

if [[ $ACTION == "get" ]] || [[ $ACTION == "delete" ]]
Expand All @@ -83,9 +93,14 @@ then
aws --profile $(get_profile) --region $region s3 cp s3://$bucket/$bucket_key logs/$STAMP/$OFILE

OFILE="lock-entry.json"
echo "* getting ddb table entry $ddbentry to logs/$STAMP/$OFILE"
aws --profile $(get_profile) --region $region dynamodb get-item --table $ddbtable --key "{\"LockID\":{\"S\":\"$ddbentry\"}}" > logs/$STAMP/$OFILE
echo ""
if [ ! -z "$ddbtable" ]
then
echo "* getting ddb table entry $ddbentry to logs/$STAMP/$OFILE"
aws --profile $(get_profile) --region $region dynamodb get-item --table $ddbtable --key "{\"LockID\":{\"S\":\"$ddbentry\"}}" > logs/$STAMP/$OFILE
echo ""
else
echo "* no ddb table defined"
fi
fi

if [[ $ACTION == "delete" ]]
Expand All @@ -94,9 +109,14 @@ then
echo "* deleting bucket s3://$bucket/$bucket_key"
aws --profile $(get_profile) --region $region s3 rm s3://$bucket/$bucket_key

echo "* deleting ddb table entry $ddbentry"
aws --profile $(get_profile) --region $region dynamodb delete-item --table $ddbtable --key "{\"LockID\":{\"S\":\"$ddbentry\"}}"
echo ""
if [ ! -z "$ddbtable" ]
then
echo "* deleting ddb table entry $ddbentry"
aws --profile $(get_profile) --region $region dynamodb delete-item --table $ddbtable --key "{\"LockID\":{\"S\":\"$ddbentry\"}}"
echo ""
else
echo "* no ddb table defined"
fi
fi

if [[ $ACTION == "put" ]]
Expand All @@ -122,12 +142,17 @@ then
echo "* making directory logs/$STAMP"
mkdir -p logs/$STAMP
OFILE="lock-entry.json"
echo "* getting previous ddb table entry $ddbentry to logs/$STAMP/$OFILE"
aws --profile $(get_profile) --region $region dynamodb get-item --table $ddbtable --key "{\"LockID\":{\"S\":\"$ddbentry\"}}" > logs/$STAMP/$OFILE

echo "* updating ddb table entry $ddbentry with value $VALUE"
aws --profile $(get_profile) --region $region dynamodb put-item --table $ddbtable --item "{\"LockID\":{\"S\":\"$ddbentry\"},\"Digest\":{\"S\":\"$VALUE\"}}"
echo ""
if [ ! -z "$ddbtable" ]
then
echo "* getting previous ddb table entry $ddbentry to logs/$STAMP/$OFILE"
aws --profile $(get_profile) --region $region dynamodb get-item --table $ddbtable --key "{\"LockID\":{\"S\":\"$ddbentry\"}}" > logs/$STAMP/$OFILE

echo "* updating ddb table entry $ddbentry with value $VALUE"
aws --profile $(get_profile) --region $region dynamodb put-item --table $ddbtable --item "{\"LockID\":{\"S\":\"$ddbentry\"},\"Digest\":{\"S\":\"$VALUE\"}}"
echo ""
else
echo "* no ddb table defined"
fi
fi

exit $?

0 comments on commit 863fec2

Please sign in to comment.