Skip to content

Instantly share code, notes, and snippets.

@alexlovelltroy
Created September 6, 2018 08:51
Show Gist options
  • Save alexlovelltroy/eed4c8523d833907144c79052352bdf6 to your computer and use it in GitHub Desktop.
Save alexlovelltroy/eed4c8523d833907144c79052352bdf6 to your computer and use it in GitHub Desktop.
Bash snippet I use to create a temporary GCP project for doing datalab stuff
#!/usr/bin/bash
set -e
PROJECT_SUFFIX=$(cat /dev/random | LC_CTYPE=C tr -dc "a-z0-9" | head -c 5)
PROJECT_NAME=temp-project-$PROJECT_SUFFIX
PROJECT_BUCKET=data_export_bucket-$PROJECT_SUFFIX
# Update gcloud
gcloud components update
gcloud components install beta gsutil bq datalab
# $MY_BILLING_ACCOUNT should be set outside this file. You can find yours with:
# gcloud beta billing accounts list
# Create a new project
gcloud projects create $PROJECT_NAME
# Enable Billing
gcloud beta billing projects link $PROJECT_NAME --billing-account $MY_BILLING_ACCOUNT
sleep 60
# Create the storage bucket
gsutil mb -p $PROJECT_NAME gs://$PROJECT_BUCKET
# Set the project
gcloud config set project $PROJECT_NAME
# Create the datalab instance
gcloud services enable compute.googleapis.com sourcerepo.googleapis.com
datalab create --zone us-west2-a temp-datalab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment