Skip to content

Instantly share code, notes, and snippets.

@mr-pascal
Created January 14, 2021 05:22
Show Gist options
  • Save mr-pascal/ce1aa6351b72571efb6ea8fdd7601122 to your computer and use it in GitHub Desktop.
Save mr-pascal/ce1aa6351b72571efb6ea8fdd7601122 to your computer and use it in GitHub Desktop.
## create-sa.sh
#### Variables
SERVICE_ACCOUNT_ID="customer-1"
PROJECT_ID="my-medium-demo-project-299218"
SA_DESCRIPTION="Customer 1 description"
SA_DISPLAY_NAME="Customer 1"
ROLE_NAME="roles/cloudfunctions.invoker"
####
### Create service account
gcloud iam service-accounts create $SERVICE_ACCOUNT_ID \
--project="$PROJECT_ID" \
--description="$SA_DESCRIPTION" \
--display-name="$SA_DISPLAY_NAME"
### Add Policy Binding / Role to service account
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member="serviceAccount:$SERVICE_ACCOUNT_ID@$PROJECT_ID.iam.gserviceaccount.com" \
--role="$ROLE_NAME"
### Print list of service accounts
gcloud iam service-accounts list \
--project="$PROJECT_ID"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment