Course contentsShow
← Cloud and Infrastructure
Lesson 87 of 2,9892. Compute FoundationsFree lesson

User Data and Cloud-Init

Using user data scripts to automate VM initialization, cloud-init syntax, and common configuration patterns.

User Data and Cloud-Init

What you'll learn: How to automatically configure and customize your VMs at launch time using user data scripts and cloud-init.

What is User Data?

User data is a script or configuration you provide when launching a VM that runs automatically during the first boot. Think of it like giving your VM a "to-do list" that it completes as soon as it starts up—installing software, creating users, or configuring settings without you logging in manually.

How Cloud-Init Works

Cloud-init is the industry-standard tool that processes user data on Linux VMs. When your VM starts, cloud-init reads your user data from the instance metadata service (remember that from the previous lesson?) and executes it.

You can provide user data in two main formats:

Shell scripts – Start with #!/bin/bash and write regular commands:

#!/bin/bash
yum update -y
echo "Hello from my VM" > /var/www/html/index.html

Cloud-config – A YAML-based declarative format that's more powerful:

#cloud-config
packages:
  - nginx
  - git
runcmd:
  - systemctl start nginx

Common Use Cases

User data helps you:

  • Install and configure web servers at launch
  • Set up monitoring agents automatically
  • Create users and SSH keys
  • Download application code from repositories
  • Configure system settings and environment variables

This automation means every VM you launch is ready to work immediately, without manual setup steps.

Key Takeaway: User data scripts and cloud-init automate VM initialization, letting you configure instances consistently and automatically at launch time—turning infrastructure deployment into a repeatable, hands-off process.