I am trying to set up an Instance using an Instance Template in the GCP Deployment Manager. It works fine but upon adding startup-script in metadata, it doesn't.
This is the code (and script) I am trying to run:
gcloud compute instances create my-instance --source-instance-template my-it --zone=northamerica-northeast1-a --network=my-network --subnet=my-subnet --no-address --metadata=startup-script='sudo /opt/scripts/startup.sh #! /bin/bash sudo htpasswd -c -B -b /etc/nginx/.htpasswd test test'
Here, the following part comes from the instance template itself and I am trying to add in the latter.
sudo /opt/scripts/startup.sh
Any help appreciated, thanks!
GCP documentation says that when creating a VM from an instance template, the default behavior is to create a VM instance precisely as described in the instance template except for the instance name and zone; if you want to override an attribute, you only need to pass the new value. Create a vm instance from an instance template with overrides
You can see from the documentation that gcloud compute instance-templates has the same --metadata and --metadata-from-file flags as gcloud compute instances gcloud compute instance-templates,gcloud compute instance create
So any new value to --metadata when creating a new instance with --source-instance-template=my_template will only override the value from the instance template (no adding). The --metadata-from-file flag maybe me more suitable for your use case( new .sh with the startup-script form instance template + extra steps)