0

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!

1
  • 1
    Assuming you are trying to deploy a VM and add a start up script from a local file > cloud.google.com/compute/docs/instances/startup-scripts/…. You might want to double check the syntax ... --metadata-from-file=startup-script=sudo /opt/scripts/startup.sh Commented Apr 21, 2022 at 21:06

1 Answer 1

3

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)

Sign up to request clarification or add additional context in comments.

1 Comment

That clears it up, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.