Skip to content

Commit

Permalink
check for actions before executing, add plans and plan output
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Jul 8, 2026
1 parent 94f46e7 commit d59ca8a
Showing 1 changed file with 62 additions and 28 deletions.
90 changes: 62 additions & 28 deletions local-app/python-tools/idc-membership-check/user_update.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
#!/bin/bash

cleanup()
{
local rstatus=$?
if [[ ! -z $TMPDIR ]] && [[ -e $TMPDIR ]]
then
rm -rf $TMPDIR
fi
exit $rstatus
}
trap cleanup EXIT

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

# variables passed by caller
# SUMMARY_CSV=/path/to/idc_reconcile.summary.csv
Expand Down Expand Up @@ -52,51 +64,73 @@ u_pending_add=$(awk -F, 'NR>1 { if ($1=="USER" && $6==1) { print $2 }}' $SUMMARY
c_pending_add=$(awk -F, 'NR>1 { if ($1=="USER" && $6==1) { c+=1 }} END {print c}' $SUMMARY_CSV)
echo "PROGRESS:$C/$TASKS" > "$STATUS_PIPE"

set -euo pipefail
C=$(( C + 1 ))
text="$C/$TASKS: tf-apply targets (add)"
echo "## $text"
echo $text > "$STATUS_PIPE"
targets=""
for u in $u_add
do
targets+=" -target=data.ldap_object.users[\"$u\"]"
targets+=" -target=aws_identitystore_user.users[\"$u\"]"
done
tf-apply -auto-approve $targets
status=$?
if [ $ADD_COUNT -gt 0 ]
then
targets=""
for u in $u_add
do
targets+=" -target=data.ldap_object.users[\"$u\"]"
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 summary
tf-apply -refresh=false $TMPDIR/user_add.json
status=$?
fi
set +euo pipefail

C=$(( C + 1 ))
text="$C/$TASKS: remove users from .csv"
echo "## $text"
echo $text > "$STATUS_PIPE"
for u in $u_delete
do
sed -i -e "/^$u\b/d" users.csv
done
status=$?
if [ $DELETE_COUNT -gt 0 ]
then
for u in $u_delete
do
sed -i -e "/^$u\b/d" users.csv
done
status=$?
fi

C=$(( C + 1 ))
text="$C/$TASKS: remove users from .yml files"
echo "## $text"
echo $text > "$STATUS_PIPE"
for u in $u_delete
do
sed -i -e "/- $u\b/d" $(rg -g "*.yml" -l -- "- $u")
done
status=$?

if [ $DELETE_COUNT -gt 0 ]
then
for u in $u_delete
do
sed -i -e "/- $u\b/d" $(rg -g "*.yml" -l -- "- $u")
done
status=$?
fi

set -euo pipefail
C=$(( C + 1 ))
text="$C/$TASKS: tf-apply targets (delete)"
echo "## $text"
echo $text > "$STATUS_PIPE"
targets=""
for u in $u_delete
do
targets+=" -target=data.ldap_object.users[\"$u\"]"
targets+=" -target=aws_identitystore_user.users[\"$u\"]"
done
tf-destroy -auto-approve $targets
status=$?
if [ $DELETE_COUNT -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
#tf-destroy -auto-approve $targets
tf-plan -refresh=false -destroy -out=$TMPDIR/user_delete.json $targets
tf-plan summary
tf-apply -refresh=false -destroy $TMPDIR/user_delete.json
status=$?
fi
set +euo pipefail

#echo "RESULT:SUCCESS:$c_add:$c_delete:$c_pending_add" > "$STATUS_PIPE"
#echo "RESULT:FAILURE:0:0:0" > "$STATUS_PIPE"
Expand Down

0 comments on commit d59ca8a

Please sign in to comment.