Create a VM with a Startup Script

Use a startup script to automate the configuration of your VM.

  1. Login to your google cloud console

  2. Go to Compute Engine

  3. Here, we will create vm instance with startup script. So, let’s get started!

  4. Name your vm instance and give the region and make sure to Allow HTTP and HTTPS traffic

  5. Scroll down on this page and click Advanced options

  6. Under Management you will find Automation, in this Startup script box we will write our script which we want to automate.

    This script will run whenever our instance boots up or restarts.

  7. In this box, I’m writing a script which will install the apache and commands for that are mentioned below

      #! /bin/bash
      apt update
      apt -y install apache2
      cat <<EOF > /var/www/html/index.html
      <html><body><p>Linux startup script added directly.</p></body></html>
      EOF
    
  8. Click on create.

  9. Now, copy the External IP and hit it into the browser

  10. You should see an output similar to what is shown below.

    You’ve just automated your VM setup with a startup script—nice work! Next, we’ll take things further by showing you how to seamlessly connect to your VM using SSH from Google Cloud Console or the terminal. Don’t miss the next post for more hands-on cloud mastery!