Skip to content

Instantly share code, notes, and snippets.

@cgaete
Created April 18, 2019 04:04
Show Gist options
  • Save cgaete/74aed4251500d0c6d0975daaf83795d9 to your computer and use it in GitHub Desktop.
Save cgaete/74aed4251500d0c6d0975daaf83795d9 to your computer and use it in GitHub Desktop.
Deploy a Compute Instance with a Remote Startup Script
#!/bin/bash
apt-get update
apt-get install -y apache2
#------------------------
PROJECT_ID="id_projecto"
#crear bucket, el nombre debe ser unico en internet
gsutil mb gs://$PROJECT_ID
#copiar archivo al bucket creado
gsutil cp resources-install-web.sh gs://$PROJECT_ID
#---------------FIN 1--------------------------
#crear maquina virtual y levantar el servicio http desde el script pasado como parametro en metadata.
gcloud compute --project=$PROJECT_ID instances create instance-1 --zone=us-central1-a --tags=http --metadata=startup-script-url=gs://$PROJECT_ID/resources-install-web.sh --scopes=https://www.googleapis.com/auth/devstorage.read_only
#Crear regla de firewall que expone la máquina virtual
gcloud compute --project=$PROJECT_ID firewall-rules create default-allow-http --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:80 --source-ranges=0.0.0.0/0 --target-tags=http-server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment