Merge "Revert "Remove the -only CLI option for packer build""
[releng/global-jjb.git] / shell / capture-instance-metadata.sh
index cb0081f..a5914ad 100644 (file)
 echo "---> capture-instance-metadata.sh"
 
 # detect if we're in EC2
-if [ -z "${NOMAD_DC}" ]; then
+if [ -n "${NOMAD_DC}" ]; then
     echo "INFO: Running in Nomad, no metadata"
     exit 0
 fi
 
-# detect if we're in AWS
-if grep -qi amazon /sys/devices/virtual/dmi/id/bios_vendor ; then
-    echo "INFO: Running in AWS, not capturing instance metadata"
-    exit 0
+# AWS not supported, exit
+cloudtype="$(jq -r .v1.datasource /run/cloud-init/result.json)"
+if [[ $cloudtype == "DataSourceEc2Local" ]]; then
+   echo "INFO: Running in AWS, not capturing instance metadata"
+   exit 0
 fi
 
 # Retrive OpenStack instace metadata APIs at this IP.