Search code examples
google-cloud-platformgoogle-cloud-vm

Why do we need Startup Script in Google Cloud VM Instance Metadata and not in Automation


Google Cloud VM Instance Wizard

In the above image, I am trying to create a VM instance on Google Cloud Platform. The wizard has options to add a startup script. The startup scripts could be added in the Automation section. In this section, we could provide the code for the startup script.

But why, as a standard practice, is it always asked to provide metadata with key startup-script-url and provide location of the script as the value?


Solution

  • It's a best practice with the pattern "separation of concern". You can dissociate the VM configuration and it's startup configuration.

    If you have to reuse the startup script (very useful in a cluster with a managed instance group and instance template).

    It's also much easier to update a file in Cloud Storage than updating the VM automation part by API.

    Finally, the separation of concern propose to separate the code (the startup script) from the configuration, especially when you use IaC (infra as code, like terraform) tool.


    But you can still use the automation part, for single VM or test purpose.