Skip to content

Instantly share code, notes, and snippets.

@glacion
Created February 15, 2020 20:29
Show Gist options
  • Save glacion/5026077fe60084f00ada64a09dfbfcb7 to your computer and use it in GitHub Desktop.
Save glacion/5026077fe60084f00ada64a09dfbfcb7 to your computer and use it in GitHub Desktop.
Setup an ubuntu server with http and https access on GCP.
#!/bin/bash
# Exit when any command fails
set -e
function log() {
echo "$(tput setaf 2)==> $(tput setaf 7)$@"
}
log 'Checking for SSH key.'
if [ ! -f ~/.ssh/id_rsa ]
then
log 'Creating SSH Key.'
ssh-keygen -N "" ~/.ssh/id_rsa
else
log 'SSH key found.'
fi
log 'Creating HTTP rule.'
gcloud compute 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
log 'Creating HTTPS rule.'
gcloud compute firewall-rules create \
default-allow-https \
--direction=INGRESS \
--priority=1000 \
--network=default \
--action=ALLOW \
--rules=tcp:443 \
--source-ranges=0.0.0.0/0 \
--target-tags=https-server
log 'Creating instance.'
gcloud compute instances create \
zarupa \
--tags=http-server,https-server \
--image-family=ubuntu-1804-lts \
--image-project=ubuntu-os-cloud \
--hostname=zarupa.internal
log 'Configuring SSH.'
gcloud compute config-ssh --ssh-key-file=~/.ssh/id_rsa
@kunthar
Copy link

kunthar commented Feb 15, 2020

colorful logs as javascript nerds ;__;

@glacion
Copy link
Author

glacion commented Feb 15, 2020

colorful logs as javascript nerds ;__;

inb4 the update where every message is including at least 69 emojis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment