We can have a bash script fire on boot: https://cloud.google.com/compute/docs/instances/startup-scripts/linux
Adding the script with Gcloud CLI:
gcloud compute instances add-metadata VM_NAME
\
--zone=ZONE
\
--metadata=startup-script='#! /bin/bash
apt update
apt -y install apache2
cat <<EOF > /var/www/html/index.html
<html><body><p>Linux startup script added directly.</p></body></html>
EOF'
It makes more sense to have the script simply launch a file on the target machine rather than putting it all into the cli at this stage.