Placing the --zone flag and specifying it in the command would obviously prevent the prompt for the zone. However, if the zone of each instance group is different and you would like to automate this process, you could add some commands to your script that lists your instance group (the output will include the zone) and then filter the output to create a variable that contains the zone information. This variable could then be used in your gcloud compute instance-groups managed delete
command.
For example, to isolate the zone of the instance group you would like to delete you could try something like this.
gcloud compute instance-groups list | grep INSTANCE_GROUP_NAME | awk '{print $2;}'
The above command first uses grep to filter a line of information with details of the instance group you would like to delete, so before awk is applied, the information looks like this:
test-instance-group us-west1-c zone default Yes 1
The the awk '{print $2;}'
filter print out the second non-whitespace substring, which will be the zone so the following is outputted:
us-west1-c
So in terms of your script, before you execute the command to delete the instance group, you would need to set a variable for that instance groups zone. To summarise, here is how your script could look:
#!/bin/bash
### retrieve the zone information of the instance group and store it in a variable.
zonevar="$(gcloud compute instance-groups list | grep INSTANCE_GROUP_NAME | awk '{print $2;}')"
### use the variable in the gcloud command to delete the instance group.
gcloud compute instance-groups managed delete INSTANCE_GROUP_NAME --zone=$zonevar
This same logic could be applied if you wanted to apply regional information rather than zonal information.