jameschen79 / terraform-ubuntu-cloudimage-vsphere-deploy

Repo containing Terraform code to deploy Ubuntu LTS cloud images to vSphere.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deploy Ubuntu 20.04 LTS (cloud image) to vSphere with Terraform

This Terraform configuration can be used to deploy Ubuntu LTS instances to VMWare vSphere environment from an Ubuntu Cloud Image template. It includes a cloud-init file template that can be further customized to satisfy your requirements.

Prerequisites
  • Download the Ubuntu 20.04 Server cloud image

  • Upload the OVA image to your vSphere environment. Select the thin provisioned disk format if your storage system supports thin provisioning. and convert it to template.

Note
Select the thin provisioning disk format if your storage system supports it.
Note
Sections 6 (networks) and 7 (customization) will be overwritten by Terraform.
Important
Do not power on the virtual machine prior to converting to template. This will ensure cloud-init runs at first boot.
Instructions
  • Configure a Terraform backend if required.

  • Review the main.tf, variables.tf and templates/userdata.yml files to customize the configuration to suite your needs.

  • Create a terraform.tfvars file to enter your vSphere environment details and virtual machine settings. Please see an example below for convenience.

cat << EOF > terraform.tfvars
# vCenter connectivity
vsphere_server   = "192.168.1.10"
vsphere_user     = "administrator@vsphere.local"
vsphere_password = "securepassword"

# Deployment options
vsphere_datacenter = "example-datacenter01"
vsphere_datastore  = "example-datastore01"
vsphere_cluster    = "example-cluster01"
vsphere_template_name = "ubuntu-focal-20.04-cloudimg-template"

# Virtual Machine(s) configuration
vm_settings = {
  dev-vm-name-01 = {
    domain       = "example-domain.com"
    netportgroup = "dev"
    ip           = "192.168.10.10"
    subnet       = 24
    gw           = "192.168.10.1"
    nameservers  = ["192.168.1.51", "192.168.1.52"]
    cpus         = 2
    memory       = 4096
    disk         = 100
    thin         = true
    folder       = "dev-ubuntu-vms"
    user         = "example-user"
    sshkey       = "ssh-rsa AAAAAAAAAAAAAA"
  }
  prod-vm-name-01 = {
    domain       = "example-domain.com"
    netportgroup = "prod"
    ip           = "192.168.20.11"
    subnet       = 24
    gw           = "192.168.20.1"
    nameservers  = ["192.168.1.51", "192.168.1.52"]
    cpus         = 4
    memory       = 8192
    disk         = 100
    thin         = true
    folder       = "prod-ubuntu-vms"
    user         = "example-user"
    sshkey       = "ssh-rsa AAAAAAAAAAAAAA"
  }
}
EOF
  • Run terraform [init, plan, apply] as usual.

About

Repo containing Terraform code to deploy Ubuntu LTS cloud images to vSphere.

License:MIT License


Languages

Language:HCL 100.0%