Create a VM with a Startup Script
Use a startup script to automate the configuration of your VM.
Login to your google cloud console
Go to Compute Engine
Here, we will create vm instance with startup script. So, let’s get started!
Name your vm instance and give the region and make sure to Allow HTTP and HTTPS traffic
Scroll down on this page and click Advanced options
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.
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
Click on create.
Now, copy the External IP and hit it into the browser
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!