Reputation: 99
I can't create instance in GCP with gcloud console:
1. If script local, everything it OK:
gcloud compute instances create app \
--boot-disk-size=10GB \
--image-family ubuntu-1604-lts \
--image-project=ubuntu-os-cloud \
--machine-type=g1-small \
--restart-on-failure \
--metadata-from-file startup-script=install.sh
2. If I user startup-script-url with gsutil URI, like this:
gcloud compute instances create app \
--boot-disk-size=10GB \
--image-family ubuntu-1604-ltsm \
--image-project=ubuntu-os-cloud \
--machine-type=g1-small \
--restart-on-failure \
--metadata-from-file startup-script-url=gs://mbps54/install.sh
Then I received:
ERROR: (gcloud.compute.instances.create) Unable to read file [gs://mbps54/install.sh]. [Errno 2] No such file or directory: 'gs://mbps54/install.sh' gsutil URI is gs://mbps54/install.sh
3. If I user startup-script-url with Public URL,like this:
gcloud compute instances create reddit-app \
--boot-disk-size=10GB \
--image-family ubuntu-1604-ltsm \
--image-project=ubuntu-os-cloud \
--machine-type=g1-small \
--restart-on-failure \
--metadata-from-file startup-script-url=https://storage.googleapis.com/mbps54/install.sh
I received:**
ERROR: (gcloud.compute.instances.create) Unable to read file [https://storage.googleapis.com/mbps54/install.sh]: [Errno 2] No such file or directory: 'https://storage.googleapis.com/mbps54/install.sh'
4. Here are my bucket settings
And I can open https://storage.googleapis.com/mbps54/install.sh from any other PC. Additionally, to make sure access is public, I did this:
gsutil defacl set public-read gs://mbps54
gsutil -m acl set -R -a public-read gs://mbps54
5. This bucket url is Public and opens from any PC https://storage.googleapis.com/mbps54/install.sh opens from other PC.
Could somebody help, what is wrong with my configuration and script?
Upvotes: 3
Views: 1454
Reputation: 2593
You're using the --metadata-from-file
flag, which expects you to supply a local file. If you want to specify a startup script from a URL instead, you want the --metadata
flag, i.e.:
--metadata startup-script-url=URL
This is mentioned at https://cloud.google.com/compute/docs/startupscript#startupscriptrunninginstances under the gcloud
tab.
Using the gcloud command-line tool, use the instances add-metadata command to add metadata to the instance. Use any of the available startup script keys:
--metadata startup-script=CONTENTS
: supply the startup script contents directly by using this key.
--metadata startup-script-url=URL
: supply a Cloud Storage URL to the startup script file by using this key. `--metadata-from-file
startup-script=FILE
: supply a locally stored startup script file.For example:
--metadata-from-file startup-script=PATH_TO_FILE gcloud compute instances add-metadata EXAMPLE_INSTANCE \ --metadata startup-script-url=gs://BUCKET/FILE ```
Upvotes: 4