Skip to content

Instantly share code, notes, and snippets.

@dukenmarga
Last active October 26, 2024 10:16
Show Gist options
  • Select an option

  • Save dukenmarga/b6152259b3255c6e1aed4c245e9bf804 to your computer and use it in GitHub Desktop.

Select an option

Save dukenmarga/b6152259b3255c6e1aed4c245e9bf804 to your computer and use it in GitHub Desktop.
Gcloud
Deploy Function
gcloud config set project $PROJECT_ID
gcloud functions deploy $FUNCTION_NAME \
  --runtime $RUNTIME --set-env-vars "GCP_PROJECT=$PROJECT_ID" \
  --trigger-http --allow-unauthenticated \
  --update-labels feature=$FEATURE_LABEL \
  --docker-registry=artifact-registry
Delete Function
gcloud functions delete $FUNCTION_NAME --project $PROJECT_ID --region asia-northeast1 --quiet

Source: https://www.youtube.com/watch?v=SDhMwyyd9_0

Upload your own Public Key
gcloud iam service-accounts keys upload PUB_KEY_FILE --iam-account=SERVICE_ACCOUNT
Generate Private Key
gcloud iam service-accounts keys create OUTPUT_FILE --iam-account=SERVICE_ACCOUNT
Accessing Google APIs using Key on the fly

This will send access token to IAM API and then generate Private Key. Private key can be used to access GCP resources.

curl --request POST --header "Authorization: Bearer $(gcloud auth print-access-token)" 'https://iam.googleapis.com/v1/projects/-/serviceAccounts/SERVICE_ACCOUNT_EMAIL/keys'
Get list of all Keys
gcloud iam service-accounts keys list --iam-account=SERVICE_ACCOUNT
Delete a Key
gcloud iam service-accounts keys delete KEY_ID --iam-account=SERVICE_ACCOUNT
Impersonate a service account
gcloud GROUP COMMAND --impersonate-service-account SERVICE_ACCOUNT
Auth Default Credential
gcloud auth application-default login
Get Current Project
gcloud config get-value project
Get info
gcloud info
Get config help
gcloud config --help
Get interactive mode
gcloud beta interactive
Tips to set the project

Instead of relying on the environment variables, it is recommended to set the project explicitly.

gcloud ... --project=${PROJECT}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment