Here is what I am doing:
gcloud compute instances create example-instance \ --image-family $image \ --image-project $projectID \ --machine-type $type_machine \ --metadata startup-script='#!/bin/bash mkdir -p ~/test'
This look super simple. The instance is created no test folder is created in home directory. I checked the VM logs I can't find anything. So this means we can not create a folder in home directory with GCP VM startup script? Or is there any thing I am missing?
- Checked the VM logs but didnt find anything.
- Was manually able to create folder in home directory after the VM is created.
According to your script and to the logs, your folder is correctly created in the home folder.
But the home folder of which user?? You are using a path shortcut ~/ but for who?
In the documentation, it's mentioned that the startup script is launched as "root" user. When you, user "Learning", ssh to the VM, a /home/learning/ home directory is created.
And it's obviously not the same as the root user.