4 Answers
Your solution is pretty similar to what I came up with when I was doing this exercise myself. And you’re right, it’s a challenging thing to do, but hopefully, you’ve learned a lot in the process. Nicely done!
One minor thing you could consider is how to set up the Service Account to use the Least Privilege required, as opposed to the Full API access. One of the upcoming chapters covers this in more detail if you’re interested. You can also use variables to make it easier to track some things, like the Project ID, Bucket Name, etc. But both of those are more "Something extra" rather than "something needed"
In terms of the points about scripting, I have some advice. None of this is required for passing the GCP ACE Exam as far as I know, but it’s interesting all the same
You can add all of your commands effectively into a file, with a simple header and it becomes a script. When you run the script, those commands are then executed sequentially. Put your commands into a single file, and name it whatever you choose; like challenge.sh
#!/bin/bash gcloud projects list gcloud projects create rudra-challenge-lab-project gcloud config set project rudra-challenge-lab-project ...
Once you’ve done that, you just need to mark the script as executable, which will then be able to run. This is done with the chmod command
chmod +x challenge.sh
Then you can run the script, and it will execute all of your commands.
./challenge.sh
Rudra,
Thanks very much for posting this. I was stuck on the billing account part. I forgot about the alpha and beta version of the gcloud command.
Hello Everyone!
i have a question regarding startup scripts. Why do we need it in order to create a vm instance. I mean what is the benefit of running scripts?
this is my gcloud commands in order. Assumptions are that
1. you have set up a billing account with your admin account like explained at the begining of the course
2. you are logged in with your user account
3. you do not have a project
4. a maximum of 3 projects can be linked to a trial billing account. If you have setup a billing project for the bigquery export, then make sure that your user account have a single project at most currently linked to your trial_billing_account
so that you can create a new project for this lab
5. copy the startup script in your home folder, with name acg_startup_script.sh
my solution (not perfect)
gcloud projects create --set-as-default --name=sandbox
# project sandbox-273609 created
gcloud beta billing accounts list
# trial billing account has ID 02BFE6-CC7730-C245EF (has been changed)
gcloud beta billing projects link sandbox-273609 --billing-account=02BFE6-CC7730-C245EF
gsutil mb -l europe-west6 gs://my-sandbox-32id gcloud compute instances list # this enables the compute api
gcloud compute instances create --machine-type=f1-micro --zone=europe-west6-b --metadata-from-file=startup-script=acg_startup_script.sh --metadata=lab-logs-bucket=gs://my-sandbox-32id/ --scopes=https://www.googleapis.com/auth/devstorage.read_write my-sandbox-instance
gcloud compute instances tail-serial-port-output my-sandbox-instance --zone=europe-west6-b
# follow logs
gsutil ls
gsutil ls gs://my-sandbox-32id/
gcloud projects delete sandbox-273609
Thank you very much Stephen. I will try the options