-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.sh
executable file
·48 lines (37 loc) · 1.81 KB
/
config.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#
# Authenticate with gcloud
#!/bin/bash
# Define environment variables
PROJECT_NAME="CryptoPulse"
PROJECT_ID="project-cryptopulse-1"
SERVICE_ACCOUNT_NAME="terraform-executor"
BILLING_ACCOUNT_ID="0178D0-832F47-2F8729"
KEY_PATH="../secrets/cryptopulse-secret.json" # Path where the service account key will be saved
# Authenticate with gcloud (commented out if you want to run it manually)
# gcloud auth login
# Create a new project
gcloud projects create $PROJECT_ID --name=$PROJECT_NAME
echo "Project $PROJECT_NAME created."
# Link project to the billing account
gcloud alpha billing projects link $PROJECT_ID --billing-account=$BILLING_ACCOUNT_ID
echo "Project $PROJECT_ID linked to billing account $BILLING_ACCOUNT_ID."
# Set the project to be the current project
gcloud config set project $PROJECT_ID
# Create a service account
gcloud iam service-accounts create $SERVICE_ACCOUNT_NAME \
--description="Service account for BigQuery access" \
--display-name="SentiStocks Service Account"
echo "Service account $SERVICE_ACCOUNT_NAME created."
# Bind BigQuery Administrator role to the service account
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member="serviceAccount:${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com" \
--role="roles/bigquery.admin"
echo "BigQuery Administrator role granted to $SERVICE_ACCOUNT_NAME."
# Create and download the service account key
gcloud iam service-accounts keys create $KEY_PATH \
--iam-account "${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com"
echo "Service account key created and downloaded to $KEY_PATH."
# Activate the service account with gcloud
gcloud auth activate-service-account --key-file=$KEY_PATH
echo "Service account activated in gcloud configuration."
echo "Setup complete. You're now using your service account with gcloud."