From d2e82683fc0aba2ae65a9ccc025c90b840752dc1 Mon Sep 17 00:00:00 2001 From: badra001 Date: Fri, 10 Oct 2025 11:56:44 -0400 Subject: [PATCH] change how to pull profile --- local-app/bin/manage-remote-state.sh | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/local-app/bin/manage-remote-state.sh b/local-app/bin/manage-remote-state.sh index 208aa7d9..1e8ae811 100755 --- a/local-app/bin/manage-remote-state.sh +++ b/local-app/bin/manage-remote-state.sh @@ -1,6 +1,6 @@ #!/bin/bash -VERSION="1.2.0" +VERSION="1.2.1" THIS=$(basename $0 .sh) test -r /apps/terraform/etc/aws-functions.sh && source /apps/terraform/etc/aws-functions.sh @@ -38,6 +38,11 @@ fi STAMP=$(date +%Y%m%d.%s) +profile=$(grep -E "\bprofile\b" $RSFILE | sed -e 's/^.*=//' -e 's/"//g' -e 's/ *//') +if [ -z "$profile" ] +then + profile=$(get_profile) +fi bucket=$(grep -E "\bbucket\b" $RSFILE | sed -e 's/^.*=//' -e 's/"//g' -e 's/ *//') bucket_key=$(grep -E "\bkey\b" $RSFILE | sed -e 's/^.*=//' -e 's/"//g' -e 's/ *//') region=$(grep -E "\bregion\b" $RSFILE | sed -e 's/^.*=//' -e 's/"//g' -e 's/ *//') @@ -57,12 +62,12 @@ then TFA="tfstate-archive" test -d $TFA || (mkdir $TFA && echo "* creating directory $TFA" ) echo "* syncing bucket s3://$bucket/ to $TFA" - aws --profile $(get_profile) --region $region s3 sync s3://$bucket/ ./$TFA/ + aws --profile $profile --region $region s3 sync s3://$bucket/ ./$TFA/ if [ ! -z "$ddbtable" ] then echo "* archiving ddb table $ddbtable" - aws --profile $(get_profile) --region $region dynamodb scan --table $ddbtable > ./$TFA/$ddbtable.json + aws --profile $profile --region $region dynamodb scan --table $ddbtable > ./$TFA/$ddbtable.json echo "" else echo "* no ddb table defined" @@ -72,12 +77,12 @@ 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 + aws --profile $profile --region $region s3 ls s3://$bucket/$bucket_key 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\"}}" + aws --profile $profile --region $region dynamodb get-item --table $ddbtable --key "{\"LockID\":{\"S\":\"$ddbentry\"}}" echo "" else echo "* no ddb table defined" @@ -90,13 +95,13 @@ then mkdir -p logs/$STAMP OFILE=$(basename $bucket_key) echo "* getting bucket s3://$bucket/$bucket_key to logs/$STAMP/$OFILE" - aws --profile $(get_profile) --region $region s3 cp s3://$bucket/$bucket_key logs/$STAMP/$OFILE + aws --profile $profile --region $region s3 cp s3://$bucket/$bucket_key logs/$STAMP/$OFILE OFILE="lock-entry.json" 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 + aws --profile $profile --region $region dynamodb get-item --table $ddbtable --key "{\"LockID\":{\"S\":\"$ddbentry\"}}" > logs/$STAMP/$OFILE echo "" else echo "* no ddb table defined" @@ -107,12 +112,12 @@ if [[ $ACTION == "delete" ]] then OFILE=$(basename $bucket_key) echo "* deleting bucket s3://$bucket/$bucket_key" - aws --profile $(get_profile) --region $region s3 rm s3://$bucket/$bucket_key + aws --profile $profile --region $region s3 rm s3://$bucket/$bucket_key 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\"}}" + aws --profile $profile --region $region dynamodb delete-item --table $ddbtable --key "{\"LockID\":{\"S\":\"$ddbentry\"}}" echo "" else echo "* no ddb table defined" @@ -145,10 +150,10 @@ then 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 + aws --profile $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\"}}" + aws --profile $profile --region $region dynamodb put-item --table $ddbtable --item "{\"LockID\":{\"S\":\"$ddbentry\"},\"Digest\":{\"S\":\"$VALUE\"}}" echo "" else echo "* no ddb table defined"