cloud-native-toolkit / cloud-native-toolkit/software-everywhere

Account purge script

Open
#187 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
8
Forks
8
PR merge metrics
No merged PRs in 30d

Description

Need a script to purge all assets from an account. Perhaps we setup this to run on a regular basis.

Here is a starter script from @seansund:
It will delete all resources created by a specified user,

```
#!/bin/bash

USERNAME="$1"

if [[ -z "${USERNAME}" ]]; then
echo "usage: delete-resources.sh USERNAME" >&2
echo " where: USERNAME is the email address of the user" >&2
exit 1
fi

if ! command -v jq 1> /dev/null 2> /dev/null; then
echo "jq cli not found" >&2
exit 1
fi

if ! command -v ibmcloud 1> /dev/null 2> /dev/null; then
echo "ibmcloud cli not found" >&2
exit 1
fi

USERID=$(ibmcloud account users --output json | jq --arg USERNAME "${USERNAME}" -r '.[] | select(.userId == $USERNAME) | .ibmUniqueId')

if [[ -z "${USERID}" ]]; then
echo "Unable to find user: ${USERNAME}" >&2
exit 1
else
echo "Found userid for username(${USERNAME}): ${USERID}"
fi

ibmcloud resource service-instances --output json | jq --arg USERID "${USERID}" -r '.[] | select(.created_by==$USERID) | .id' | \
while read id; do
ibmcloud resource service-keys --instance-id "${id}" --output json | jq -r '.[] | .id' | \
while read key_id; do
ibmcloud resource service-key-delete "${key_id}" --force
done

ibmcloud resource service-instance-delete "${id}" --force
done
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.