In google cloud ,we mark custom images deprecated after a specific time. how can we get report of the VM instances which are using the deprecated image?
thanks
In order to view all the deprecated images available in GCE, as seen in Debian's documentation use the below command:
gcloud compute images list --project=name-of-your-project --no-standard-images --show-deprecated
Then view source image with
gcloud compute disk list
Use the disk describe command with a --format flag to filter the output.
gcloud compute disks describe disk_name --zone zone_1 --format='get(sourceImage)'
Creating a script that checks all the deprecated images with all disks used by VMs could do the trick
for project in $(gcloud projects list --format "value(project_id)");
do if [ $(gcloud services list --filter 'config.name="compute.googleapis.com"' --project $project --format 'value(name)' ) ];
then for instance in $(gcloud compute instances list --format "value(selfLink)" --project $project);
do for sources in $(gcloud compute instances describe $instance --project $project --format "value(disks.source)" );
do for source in $(echo $sources | tr \; \\n);
do sourceimage=$(gcloud compute disks describe $source --project $project --format='get(sourceImage)' );
if [ ! -z $sourceimage ];
then state=$(gcloud compute images describe $sourceimage --project $project --format "value(deprecated.state)" 2>/dev/null);
if [ ! -z $state ];
then if [ $state == DEPRECATED ];
then echo $instance;
fi;
fi;
fi;
done;
done;
done;
fi;
done | sort | uniq
Keep in mind that it will need some time because the loop has to go project by project.