Skip to content

Instantly share code, notes, and snippets.

@The-OMG
Last active July 27, 2019 17:35
Show Gist options
  • Save The-OMG/1bebee7df4a57029f1651c6ad36eca1d to your computer and use it in GitHub Desktop.
Save The-OMG/1bebee7df4a57029f1651c6ad36eca1d to your computer and use it in GitHub Desktop.
Small script for creating Google Cloud Service Accounts
#!/bin/bash
# requires gcloud command line tools
# go to https://cloud.google.com/sdk/docs/quickstarts to get them OR you can install with Node (npm) "npm install --save -g @google-cloud/cloud-sdk"
# max 100 service accounts per project
# run "gcloud init --console-only" first and select a project; run it again to select another project to create more service accounts
# Location of where service account keys will be created
KEYS_DIR=keys
# List of 100 famous people for service account names
NAMES="abraham-lincoln adolf-hitler albert-einstein alfred-hitchcock amelia-earhart angelina-jolie anne-frank audrey-hepburn aung-san-suu-kyi babe-ruth barack-obama benazir-bhutto bill-gates billie-holiday billie-jean-king bob-geldof c-s-lewis carl-lewis charles-darwin charles-de-gaulle christopher-columbus cleopatra coco-chanel dalai-lama david-beckham desmond-tutu donald-trump elvis-presley ernest-hemingway eva-peron fidel-castro franklin-d-roosevelt george-bush-jnr george-orwell grace-kelly haile-selassie henry-ford indira-gandhi ingrid-bergman j-k-rowling j-r-r-tolkien jacqueline-kennedy-onassis jawaharlal-nehru jesse-owens john-f-kennedy john-lennon john-m-keynes joseph-stalin katherine-hepburn leo-tolstoy leon-trotsky leonardo-da-vinci lionel-messi lord-baden-powell louis-pasteur ludwig-beethoven lyndon-johnson madonna mahatma-gandhi malcolm-x mao-zedong margaret-thatcher marilyn-monroe martin-luther-king mary-magdalene mata-hari michael-jackson michael-jordon mikhail-gorbachev mother-teresa muhammad-ali neil-armstrong nelson-mandela oprah-winfrey oscar-wilde pablo-picasso paul-mccartney pele01 peter-sellers plato01 pope-francis pope-john-paul-ii prince-charles queen-elizabeth-ii queen-victoria richard-branson roger-federer ronald-reagan rosa-parks sigmund-freud steve-jobs sting01 thomas-edison tiger-woods usain-bolt vincent-van-gogh vladimir-lenin walt-disney winston-churchill woodrow-wilson"
FRIENDLY_NAMES=("Abraham Lincoln"
"Adolf Hitler"
"Albert Einstein"
"Alfred Hitchcock"
"Amelia Earhart"
"Angelina Jolie"
"Anne Frank"
"Audrey Hepburn"
"Aung San Suu Kyi"
"Babe Ruth"
"Barack Obama"
"Benazir Bhutto"
"Bill Gates"
"Billie Holiday"
"Billie Jean King"
"Bob Geldof"
"C. S. Lewis"
"Carl Lewis"
"Charles Darwin"
"Charles de Gaulle"
"Christopher Columbus"
"Cleopatra"
"Coco Chanel"
"Dalai Lama"
"David Beckham"
"Desmond Tutu"
"Donald Trump"
"Elvis Presley"
"Ernest Hemingway"
"Eva Peron"
"Fidel Castro"
"Franklin D. Roosevelt"
"George Bush Jnr"
"George Orwell"
"Grace Kelly"
"Haile Selassie"
"Henry Ford"
"Indira Gandhi"
"Ingrid Bergman"
"J. K. Rowling"
"J. R. R. Tolkien"
"Jacqueline Kennedy Onassis"
"Jawaharlal Nehru"
"Jesse Owens"
"John F. Kennedy"
"John Lennon"
"John M. Keynes"
"Joseph Stalin"
"Katherine Hepburn"
"Leo Tolstoy"
"Leon Trotsky"
"Leonardo da Vinci"
"Lionel Messi"
"Lord Baden Powell"
"Louis Pasteur"
"Ludwig Beethoven"
"Lyndon Johnson"
"Madonna"
"Mahatma Gandhi"
"Malcolm X"
"Mao Zedong"
"Margaret Thatcher"
"Marilyn Monroe"
"Martin Luther King"
"Mary Magdalene"
"Mata Hari"
"Michael Jackson"
"Michael Jordon"
"Mikhail Gorbachev"
"Mother Teresa"
"Muhammad Ali"
"Neil Armstrong"
"Nelson Mandela"
"Oprah Winfrey"
"Oscar Wilde"
"Pablo Picasso"
"Paul McCartney"
"Pele"
"Peter Sellers"
"Plato"
"Pope Francis"
"Pope John Paul II"
"Prince Charles"
"Queen Elizabeth II"
"Queen Victoria"
"Richard Branson"
"Roger Federer"
"Ronald Reagan"
"Rosa Parks"
"Sigmund Freud"
"Steve Jobs"
"Sting"
"Thomas Edison"
"Tiger Woods"
"Usain Bolt"
"Vincent Van Gogh"
"Vladimir Lenin"
"Walt Disney"
"Winston Churchill"
"Woodrow Wilson")
# Initial Account Creation
parallel -j0 --link gcloud iam service-accounts create {1} --display-name {2} ::: $NAMES ::: "${FRIENDLY_NAMES[@]}"
# JSON Key creation for new accounts
# Keys will be created in your current working directory
parallel -j0 gcloud iam service-accounts keys create $KEYS_DIR/{}.json --iam-account={} ::: "$(gcloud iam service-accounts list --format='value(email)')"
# Prints out a list of the names and emails of the new accounts.
gcloud iam service-accounts list --format='value(email)'
echo ""
echo ""
echo "Share access from your google drive folders to the above emails for them to work correctly."
@The-OMG
Copy link
Author

The-OMG commented Mar 13, 2019

fixed the error being caused by the quotes around $NAMES

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