Lab: Infrastructure Automation
Objective
Section titled “Objective”Automate VergeOS infrastructure operations using the REST API, Terraform provider, and scripting tools (pyvergeos or PowerShell). By the end of this lab, you will have provisioned VMs and tenants programmatically and understand how to integrate VergeOS into CI/CD and automation workflows.
Prerequisites
Section titled “Prerequisites”- Completed Module 1: Architecture Fundamentals
- Completed Module 6: Virtual Machines
- Completed Module 7: Multi-Tenancy
- Completed Module 8 reading (REST API, Terraform, Python/PowerShell, Seed Files)
- A running VergeOS cluster with API access enabled
- Terraform installed locally (v1.5+)
- Python 3.9+ or PowerShell 7+ installed locally
- Access to the vergeos-terraform-playground repository
Difficulty
Section titled “Difficulty”Intermediate — Requires familiarity with REST APIs, infrastructure-as-code concepts, and basic scripting
Estimated Time
Section titled “Estimated Time”2 hours
Part 1: REST API Exploration
Section titled “Part 1: REST API Exploration”Authenticate with the VergeOS API and perform basic operations.
- Obtain an API token from the VergeOS UI (System > API Tokens)
- Use
curlor a REST client to authenticate:Terminal window curl -X GET https://<your-vergeos-host>/api/v4/machines \-H "x-yottabyte-token: <your-api-token>" - List all VMs using the
/api/v4/machinesendpoint - Create a new VM via the API:
- POST to
/api/v4/machineswith a JSON body specifying name, CPU, memory, and disk
- POST to
- Start and stop the VM using the API
- Delete the VM via the API
- Explore additional endpoints: networks (
/api/v4/networks), tenants (/api/v4/tenants)
Part 2: Terraform Provider
Section titled “Part 2: Terraform Provider”Use the VergeOS Terraform provider to manage infrastructure declaratively.
- Clone the vergeos-terraform-playground repository:
Terminal window git clone https://github.com/verge-io/vergeos-terraform-playground.gitcd vergeos-terraform-playground - Review the provider configuration in
main.tf - Copy and customize an example
.tfvarsfile for your environment - Run
terraform initto download the VergeOS provider - Run
terraform planto preview the infrastructure changes - Run
terraform applyto provision resources - Verify the created resources in the VergeOS UI
- Modify a resource in the Terraform configuration and re-apply
- Run
terraform destroyto clean up
Part 3: Scripting Automation
Section titled “Part 3: Scripting Automation”Automate a workflow using pyvergeos (Python) or the PowerShell module.
- Install pyvergeos:
Terminal window pip install pyvergeos - Write a script that:
- Connects to your VergeOS cluster
- Lists all VMs and their current status
- Creates a new VM from a recipe/template
- Waits for the VM to be running
- Outputs the VM’s IP address and connection details
- Extend the script to:
- Create a tenant with predefined resource allocations
- Deploy a VM inside the tenant
- Verify tenant isolation by checking network connectivity
Part 4: Cloud-Init & Seed Files
Section titled “Part 4: Cloud-Init & Seed Files”Configure unattended VM provisioning using cloud-init.
- Create a cloud-init configuration file with:
- Hostname and network settings
- User accounts and SSH keys
- Package installation commands
- Post-boot scripts
- Attach the cloud-init configuration to a new VM via the API or UI
- Boot the VM and verify that the cloud-init configuration was applied:
- Check hostname and network settings
- Verify user accounts exist
- Confirm packages were installed
- Create a reusable seed file template for standardized VM deployments
Verification
Section titled “Verification”Your infrastructure automation lab is complete when you can answer yes to all of the following:
- Successfully authenticated with the VergeOS REST API and performed CRUD operations on VMs
- Provisioned infrastructure using the Terraform provider from the playground repository
- Modified and re-applied Terraform configuration, observing incremental changes
- Created a script (Python or PowerShell) that automates VM and/or tenant provisioning
- Configured a VM with cloud-init for unattended setup and verified the configuration was applied
- Cleaned up all lab resources (VMs, tenants, Terraform state)