Skip to content

Instantly share code, notes, and snippets.

@mikesparr
Created May 18, 2025 19:41
Show Gist options
  • Save mikesparr/e82c2c826400e9fdf51b360d913ce773 to your computer and use it in GitHub Desktop.
Save mikesparr/e82c2c826400e9fdf51b360d913ce773 to your computer and use it in GitHub Desktop.
Google Cloud Secret Manager example secret as file
# create secret as file
export SECRET_ID="example-secret"
export SECRET_FILE=".env"
# create env file
cat > $SECRET_FILE << EOF
# Node environment
NODE_ENV=production
# Logging configuration
LOG_LEVEL=debug
# Server configuration
PORT=8080
HOST=0.0.0.0
# Database configuration
DATABASE_URL=postgres://$DB_USER:$DB_PASS@$POSTGRES_HOST:$POSTGRES_PORT/$DB_NAME
# ...
EOF
# create secret from env file
gcloud secrets create $SECRET_ID --replication-policy="automatic"
gcloud secrets versions add $SECRET_ID --data-file=${PWD}/$SECRET_FILE
# remove temp file
rm $SECRET_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment