Skip to content

SQLauto/Automated-Sandbox-Framework

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Automated Sandbox Framework

NEW: The SQL Server Lab Accelerator Course

This free framework gives you the tools to build a lab. The premium course teaches you how to master it.

If you want a complete, step-by-step learning experience that goes beyond the basics, enroll in the full course to learn how to:

  • Master the Lab Workflow: Go beyond setup and learn to use Snapshots to instantly save and restore your lab state.
  • Build a Full Active Directory Domain: Automatically deploy a DC and create a realistic enterprise lab.
  • Add additional disks to your VMs using automation: Add additional disks to your SQL Server VMs using automation.

Introduction

I built this framework to quickly spin up sandbox environments without needing to install Windows each time manually. It's also used by students in my courses hosted at https://www.automatesql.com, focusing on SQL Server builds using Ansible.

The Automated Sandbox Framework provides all the resources you need—HashiCorp Packer HCL templates, PowerShell scripts, autounattend files, and Vagrantfiles—to build fully automated virtual sandbox environments.

By default, it creates a Windows Server 2025 Standard Evaluation image with SSH enabled. On the first boot, each VM is sysprepped to ensure a unique SID is generated.

The included Vagrantfile can create 5 virtual machines. Consider setting up a domain controller (DC1) for a more realistic scenario. Additional secondary disks can be added manually using the VMware Workstation Pro GUI or by configuring the vagrant file to use the Vagrant Disk. However, it's not currently included.

Example Machine Roles:

  • DC1: Domain Controller
  • SRV1: Jumpbox/Tools Host
  • SQL1: SQL Server Developer
  • SQL2: SQL Server Developer
  • SQL3: SQL Server Developer

Prerequisites

  1. Host OS: Windows 11

    • Disable Hyper-V.
    • Ensure nested virtualization is supported.
      See this link for details.
  2. Hardware:

    • CPU: x64 with virtualization support .
    • Memory: 16 GB minimum (more may be needed to support larger environments).
    • Storage: At least 128 GB free.
  3. Precheck:

    • Run the precheck-virtualizationsupport.ps1 script as an Administrator. This script will check your system for potential issues with the lab setup.

Required Software

  1. VMware Workstation Pro 17 (How to install using Chocolatey) (Currently this method is broken. Follow these steps instead -

    1. Create a Broadcom account

    2. Login using your new account

    3. Go to Product Downloads

    4. Select VMware Workstation Pro (version) for Windows and proceed to download and install the software.

  2. HashiCorp Packer

  3. HashiCorp Vagrant

  4. Vagrant VMware Utility

  5. Vagrant VMware Desktop Plugin

  6. Windows Server 2025 Evaluation ISO


Building the Windows Server 2025 Evaluation Image

The win2025.pkr.hcl template leverages Packer to:

  • Install and update Windows Server 2025 automatically.
  • Install VMware Tools.
  • Enable SSH access.
  • Package everything into a Vagrant .box file, eliminating manual setup.

Key Points:

  • Requires vmware and vagrant Packer plugins.
  • Uses variables for customization (iso_checksum, memsize, numvcpus, etc.).
  • Employs the vmware-iso builder and multiple provisioners (PowerShell scripts, file uploads, restarts).
  • A final post-processor creates the .box file.

Adjusting Autounattend and Unattend Files

  1. Password:
    Update the default password ("packer") at:

    • scripts/autounattend.xml: Lines 144, 177
    • scripts/unattend.xml: Lines 64, 98
  2. Time Zone:
    Edit unattend.xml to set your preferred time zone (the default is Central Standard Time).

  3. Windows Server Edition:
    By default, the template uses Standard Evaluation (Index 2). Modify Autounattend.xml if you need a different edition:

    • Index 1: Windows Server 2025 Standard Evaluation
    • Index 2: Windows Server 2025 Standard Evaluation (Desktop Experience)
    • Index 3: Windows Server 2025 Datacenter Evaluation
    • Index 4: Windows Server 2025 Datacenter Evaluation (Desktop Experience)

Updating variables.pkrvars.hcl

  • Update iso_checksum. To get the iso checksum, use Get-FileHash pathToISO in PowerShell.
  • Adjust other variables as needed.

Running packer init

Before building, run packer init to fetch the required plugins:

cd path\to\win2025.pkr.hcl
packer init win2025.pkr.hcl

Running packer build

Build the .box file.

Start VMware Workstation Pro prior to running packer build.

cd path\to\win2025.pkr.hcl
packer build --var-file="variables.pkrvars.hcl" win2025.pkr.hcl

This step will take several minutes to complete. You'll see the image being built in VMware Workstation Pro.

Using the vagrantfile to build your sandbox.

The example vagrantfile will create 5 VMs. Modify the machines array as needed:

machines = [ 
  { name: "DC1", memory: 4096, cpus: 4, vnet: "VMnet8", nat_device: "vmnet8"},
  { name: "SRV1", memory: 8192, cpus: 4, vnet: "VMnet8", nat_device: "vmnet8" },
  { name: "SQL1", memory: 8192, cpus: 8, vnet: "VMnet8", nat_device: "vmnet8" },
  { name: "SQL2", memory: 8192, cpus: 8, vnet: "VMnet8", nat_device: "vmnet8" },
  { name: "SQL3", memory: 8192, cpus: 8, vnet: "VMnet8", nat_device: "vmnet8" }
]
  • Set config.vm.box to the path of your new .box file.
  • Set config.ssh.password to the password used during image creation.

Running vagrant up

Open either a command window and navigate to the directory where the vagrantfile resides.

  • Run vagrant up.

VMware Workstation will create the VMs. Expect a few reboots on the initial run. Subsequent startups will be much faster.

  • To shut down all VMs, run vagrant halt.

  • To completely destroy all VMs created by this vagrantfile run vagrant destroy.

For more vagrant commands see this link

This framework dramatically reduces manual setup time, making it easy to spin up multiple, fully configured Windows Server environments for testing, development, or lab scenarios.

Screenshot of virtual environment

ASF_Virtual_Environment

About

HashiCorp Packer HCL templates, Windows PowerShell scripts, Autounattend files, and HashiCorp Vagrant files to build virtual sandboxes.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • PowerShell 79.8%
  • HCL 18.6%
  • Batchfile 1.6%