Skip to content

Commit

Permalink
add -x, echo vs execute changes
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Jul 8, 2026
1 parent d59ca8a commit 726485b
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions local-app/python-tools/idc-membership-check/user_update.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash -x

cleanup()
{
Expand All @@ -12,7 +12,7 @@ cleanup()
trap cleanup EXIT

THIS=$(basename $0 .sh)
VERSION="1.1.2"
VERSION="1.1.4"
# set -euo pipefail
export TMPDIR=$(/bin/mktemp -d /tmp/user_update.XXXXXXXX) || (echo "#* error making TMPDIR" && exit 1)

Expand Down Expand Up @@ -46,6 +46,10 @@ echo "## $text"
echo $text > "$STATUS_PIPE"
u_add=$(awk -F, 'NR>1 { if ($1=="USER" && $4==1) { print $2 }}' $SUMMARY_CSV)
c_add=$(awk -F, 'NR>1 { if ($1=="USER" && $4==1) { c+=1 }} END {print c}' $SUMMARY_CSV)
if [ -z $c_add ]
then
c_add=0
fi
echo "PROGRESS:$C/$TASKS" > "$STATUS_PIPE"

C=$(( C + 1 ))
Expand All @@ -54,6 +58,10 @@ echo "## $text"
echo $text > "$STATUS_PIPE"
u_delete=$(awk -F, 'NR>1 { if ($1=="USER" && $3!="" && $5==1) { print $2 }}' $SUMMARY_CSV)
c_delete=$(awk -F, 'NR>1 { if ($1=="USER" && $3!="" && $5==1) { c+=1 }} END {print c}' $SUMMARY_CSV)
if [ -z $c_delete ]
then
c_delete=0
fi
echo "PROGRESS:$C/$TASKS" > "$STATUS_PIPE"

C=$(( C + 1 ))
Expand All @@ -62,14 +70,18 @@ echo "## $text"
echo $text > "$STATUS_PIPE"
u_pending_add=$(awk -F, 'NR>1 { if ($1=="USER" && $6==1) { print $2 }}' $SUMMARY_CSV)
c_pending_add=$(awk -F, 'NR>1 { if ($1=="USER" && $6==1) { c+=1 }} END {print c}' $SUMMARY_CSV)
if [ -z $c_pending_add ]
then
c_pending_add=0
fi
echo "PROGRESS:$C/$TASKS" > "$STATUS_PIPE"

set -euo pipefail
C=$(( C + 1 ))
text="$C/$TASKS: tf-apply targets (add)"
text="$C/$TASKS: tf-apply targets (add $c_add)"
echo "## $text"
echo $text > "$STATUS_PIPE"
if [ $ADD_COUNT -gt 0 ]
if [ $c_add -gt 0 ]
then
targets=""
for u in $u_add
Expand All @@ -78,9 +90,9 @@ then
targets+=" -target=aws_identitystore_user.users[\"$u\"]"
done
#tf-apply -auto-approve $targets
tf-plan -refresh=false -out=$TMPDIR/user_add.json $targets
tf-plan -refresh=false -out=$TMPDIR/user_add.tfplan $targets
tf-plan summary
tf-apply -refresh=false $TMPDIR/user_add.json
echo "tf-apply -refresh=false $TMPDIR/user_add.tfplan"
status=$?
fi
set +euo pipefail
Expand All @@ -89,7 +101,7 @@ C=$(( C + 1 ))
text="$C/$TASKS: remove users from .csv"
echo "## $text"
echo $text > "$STATUS_PIPE"
if [ $DELETE_COUNT -gt 0 ]
if [ $c_delete -gt 0 ]
then
for u in $u_delete
do
Expand All @@ -102,7 +114,7 @@ C=$(( C + 1 ))
text="$C/$TASKS: remove users from .yml files"
echo "## $text"
echo $text > "$STATUS_PIPE"
if [ $DELETE_COUNT -gt 0 ]
if [ $c_delete -gt 0 ]
then
for u in $u_delete
do
Expand All @@ -113,21 +125,22 @@ fi

set -euo pipefail
C=$(( C + 1 ))
text="$C/$TASKS: tf-apply targets (delete)"
text="$C/$TASKS: tf-apply targets (delete $c_delete)"
echo "## $text"
echo $text > "$STATUS_PIPE"
if [ $DELETE_COUNT -gt 0 ]
if [ $c_delete -gt 0 ]
then
targets=""
for u in $u_delete
do
targets+=" -target=data.ldap_object.users[\"$u\"]"
targets+=" -target=aws_identitystore_user.users[\"$u\"]"
done
echo "tf-destroy -refresh-false -approve $targets"
#tf-destroy -auto-approve $targets
tf-plan -refresh=false -destroy -out=$TMPDIR/user_delete.json $targets
tf-plan -refresh=false -destroy -out=$TMPDIR/user_delete.tfplan $targets
tf-plan summary
tf-apply -refresh=false -destroy $TMPDIR/user_delete.json
echo "tf-apply -refresh=false -destroy $TMPDIR/user_delete.tfplan"
status=$?
fi
set +euo pipefail
Expand All @@ -138,7 +151,7 @@ set +euo pipefail
#echo "RESULT:SUCCESS:$c_add:$c_delete:$c_pending_add" > "$STATUS_PIPE"
#echo "RESULT:FAILURE:0:0:0" > "$STATUS_PIPE"

text="END file $SUMMARY_CSV add $ADD_COUNT delete $DELETE_COUNT pending-add $PENDING_COUNT"
text="END file $SUMMARY_CSV add $c_add delete $c_delete pending-add $c_pending_add"
echo "## $text"
#echo $text > "$STATUS_PIPE"

Expand Down

0 comments on commit 726485b

Please sign in to comment.