0
0
GCPcloud~30 mins

Startup scripts for automation in GCP - Mini Project: Build & Apply

Choose your learning style9 modes available
Startup scripts for automation
📖 Scenario: You are setting up a Google Cloud virtual machine (VM) that needs to automatically install and start a web server when it boots up. This automation saves time and ensures the server is ready without manual setup.
🎯 Goal: Create a startup script that installs the Apache web server and starts it automatically on a Google Cloud VM instance.
📋 What You'll Learn
Create a startup script variable with the exact shell commands to install Apache
Add a configuration variable to specify the Apache service name
Write the core logic to include the startup script in the VM instance metadata
Complete the VM instance creation with the startup script attached
💡 Why This Matters
🌍 Real World
Automating VM setup with startup scripts is common in cloud environments to save time and reduce manual errors when deploying servers.
💼 Career
Cloud engineers and DevOps professionals use startup scripts to automate instance configuration and ensure consistent environments.
Progress0 / 4 steps
1
Create the startup script variable
Create a variable called startup_script that contains the exact shell commands to update package lists, install Apache2, and start the Apache2 service using systemctl. Use the following commands exactly: sudo apt-get update -y, sudo apt-get install apache2 -y, and sudo systemctl start apache2 separated by semicolons.
GCP
Need a hint?

Use a single string with commands separated by semicolons.

2
Add the Apache service name configuration
Create a variable called apache_service and set it to the string "apache2" to specify the Apache service name.
GCP
Need a hint?

Set the variable exactly as shown.

3
Add the startup script to VM instance metadata
Create a dictionary called instance_metadata with a key "startup-script" and set its value to the startup_script variable.
GCP
Need a hint?

Use a dictionary with the key exactly as "startup-script".

4
Complete VM instance creation with startup script
Create a dictionary called vm_instance with keys "name" set to "web-server", "machine_type" set to "n1-standard-1", and "metadata" set to the instance_metadata variable.
GCP
Need a hint?

Include all keys exactly as specified.