3 Answers
To your second question: You supply that through metadata
(select gcloud tab)
Alternatively you could play with
1. Loading the longer startup script to a bucket.
2. Referencing that location in your shorter script provided directly
FYI, below are the commands i used for the advanced revision of this lab:
gcloud projects create lab81a
gcloud config set project lab81a
gcloud alpha billing projects link (google the remaining bits pls)
gsutil mb -c standard -l us-east1 gs://lab81-adv-bucket
gcloud compute instances create lab81-ce1 --machine-type=f1-micro --preemptible
--zone us-east1-c
--metadata=startup-script-url=gs://lab81-adv-bucket/worker-startup-script.sh,lab-logs-bucket=gs://lab81-adv-bucket/
--scopes=default,storage-rw
Simplifying it, you can do like below:
#: create the new project gcloud projects create new-project005 --enable-cloud-apis
#: list billing accounts gcloud alpha billing accounts list
#: link the project and the billing account gcloud alpha billing projects link new-project005 --billing-account XXXXXXXXXXX
#: set the current session project's gcloud config set project new-project005
#: set the default region and the default zone on the cloud shell gcloud config set compute/region us-west2 gcloud config set compute/zone us-west2-b
To create an instance loading up a startup script, it a script at the home of your user on Cloud Shell instance and execute a command like the one below:
#: create the instance with the user-data script, the metadata for the bucket and the scopes for monitoring, storage and logging gcloud compute instances create myvm01 --metadata lab-logs-bucket=gs://new-project005/ --metadata-from-file startup-script=script.sh --scopes storage-rw,monitoring-write,logging-write --machine-type f1-micro --deletion-protection
I hope it helps.
-Bianchi
Thanks this is perfect!
Thank you!