1

Is there a convenient way to delete all resources in a resource group in ibmcloud? Or even delete the whole resouce group at once?

I have multiple resource groups in my account that need to be deleted with dozens of resources each. Is there a descent way to automate this via the "ibmcloud cli" or even do it via the UI?

Maximilian Jesch
  • 623
  • 7
  • 16

3 Answers3

1

I prefer to delete resources using the CLI. There are

Both commands have a force option. Some service instances can only be deleted when there are no crucial dependencies. An example might be that there is still a root key managed by Key Protect or some COS storage buckets are not empty. You need to look into how to handle that.

You should also be aware of resource reclamation. Some resources are not deleted immediately (when not explicitly stated), but retained for some days.

There is command provided to clean up everything with a single command ("oops, I deleted my enterprise resources").

There is the option to write some simple scripting by listing the resources of interest and iterating over them with the delete command.

You may want to take a look at the scripts provided for IBM Cloud solution tutorials, e.g., https://github.com/IBM-Cloud/vpc-tutorials/blob/master/scripts/vpc-cleanup.sh

data_henrik
  • 16,724
  • 2
  • 28
  • 49
  • Thank you, but the "ibmcloud resource group-delete -f" still does not let me delete the whole resource group. I have to go through all the instances and delete them individually before I can delete the ressource group. I am afraid there is no way to do this without some coding :-/ – Maximilian Jesch Jun 20 '23 at 13:11
  • 1
    I added a link to sample scripts – data_henrik Jun 20 '23 at 13:38
0

From the ui the resource list allows filtering by Group: https://cloud.ibm.com/resources. Not all resources contribute to this view. I wrote a program that does this. You can run stand alone or make it part of the ibmcloud cli: https://github.com/powellquiring/iww

Powell Quiring
  • 2,349
  • 2
  • 11
  • 9
0

Look for connected resources within an IBM Cloud account, loop to export all resources from all resource groups

ibmcloud login --apikey=

rg_list=$(ibmcloud resource groups --output json | jq -r .[].name)

for i in $rg_list; do echo "$i" && \
ibmcloud resource service-instances --type all \
-g "$i" --output json \
| jq --arg rg_name "$i" \
--raw-output \
'["Resource Name","Resource CRN","Resource Type","Region","State","Type","Created At","Updated At","Last Operation Type","Last Operation Status","Last Operation Description","Resource Group ID","Resource Group Name"]
,
(.[] | [.name, .crn, .resource_id, .region_id, .state, .type, .created_at, .updated_at, .last_operation.type, .last_operation.state, .last_operation.description, .resource_group_id, $rg_name])
| @csv' > "resources_rg_$i.csv" \
; done

echo 'Created CSV for each IBM Cloud Resource Group, merging into single CSV also'
cat *.csv | uniq > resources_all.csv
echo 'Complete'

Example of brute force resources deletion

ibmcloud is instance-delete --force $INSTANCE_ID
ibmcloud is volume-delete --force $VOL_SHORT_ID
ibmcloud dns instance-delete $DNS_SHORT_ID
ibmcloud is vpc-delete $VPC_NAME
ibmcloud resource service-instance-delete --force $CRN_HERE
ibmcloud resource service-instance-delete --force --recursive $CRN_HERE
ibmcloud resource group-delete -f $RG_NAME
seafre
  • 67
  • 2
  • 10