You cannot really directly determine from within a shutdown script that the instance is being deleted. However, using gcloud compute instance-groups managed list-instances will give you an output of the current actions on instances with the column "ACTION" and there are statuses like RESTARTING, STOPPING, or DELETING.