├── .gitignore ├── .markdownlint.json ├── LICENSE ├── README.md ├── img ├── DC_Storage_Settings.png ├── Proxmox-VE_Architecture.svg ├── mHC.png ├── pve-menu-1.png ├── pve-menu-2-select-target-disk.png ├── pve-menu-3-select-location.png ├── pve-menu-4-set-password.png ├── pve-menu-5-setup-network.png └── pve-menu-6-install-summary.png ├── packer └── packer_proxmox-clone │ ├── build.pkr.hcl │ ├── locals.pkr.hcl │ ├── sources.pkr.hcl │ ├── variables._auto.pkrvars.hcl │ ├── variables.pkr.hcl │ └── variables.pkrvars.hcl ├── proxmox-ve ├── create-proxmox-users.sh ├── create-template-via-cloudinit.sh └── sample-cloud-init-config.yml └── terraform ├── main.tf ├── provider.tf ├── terraform.tfvars ├── variables.tf └── versions.tf /.gitignore: -------------------------------------------------------------------------------- 1 | # Local .terraform directories 2 | **/.terraform/* 3 | 4 | # .tfstate files 5 | *.tfstate 6 | *.tfstate.* 7 | 8 | # Crash log files 9 | crash.log 10 | 11 | # Ignore any .tfvars files that are generated automatically for each Terraform run. Most 12 | # .tfvars files are managed as part of configuration and so should be included in 13 | # version control. 14 | # 15 | # example.tfvars 16 | 17 | # Ignore override files as they are usually used to override resources locally and so 18 | # are not checked in 19 | override.tf 20 | override.tf.json 21 | *_override.tf 22 | *_override.tf.json 23 | 24 | # Include override files you do wish to add to version control using negated pattern 25 | # 26 | # !example_override.tf 27 | 28 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan 29 | # example: *tfplan* 30 | 31 | # others 32 | **/cloud-init-config.yml -------------------------------------------------------------------------------- /.markdownlint.json: -------------------------------------------------------------------------------- 1 | { 2 | "MD013": false, 3 | "MD033": false 4 | } 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Barış Gece 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | mini Home Cloud 3 |
4 | 5 |

The easy-way to create and manage a personal cloud envirnoment. mHC has been created using Shell, Proxmox-VE, Packer, Terraform, Ansible, MAAS and is not completely reliable for Production environments.

6 | 7 | # 8 | 9 | ## Table of Contents 10 | 11 | - [Proxmox-VE](#proxmox-ve) 12 | - [Installation - Manual Step](#installation---manual-step) 13 | - [Creating Ubuntu Image](#creating-ubuntu-image) 14 | - [Installation - Script Step - Creating cloud-init Template](#installation---script-step---creating-cloud-init-template) 15 | - [For Maximum Performance](#for-maximum-performance) 16 | - [Create PVE User for Terraform, Packer & Ansible](#create-pve-user-for-terraform-packer--ansible) 17 | - [Packer](#packer) 18 | - [Installing Packer on Ubuntu Jump Server](#installing-packer-on-ubuntu-jump-server) 19 | - [Preparing Proxmox-VE template via Packer](#preparing-proxmox-ve-template-via-packer) 20 | - [Input Variables](#input-variables) 21 | - [`local` Variables](#local-variables) 22 | - [Terraform](#terraform) 23 | - [Installing Terraform on Ubuntu Jump Server](#installing-terraform-on-ubuntu-jump-server) 24 | - [Provisioning Virtual Machine on Proxmox-VE via Terraform](#provisioning--virtual-machine-on-proxmox-ve-via-terraform) 25 | - [Terraform Input Variables](#terraform-input-variables) 26 | - [Terraform Proxmox Provider Variables](#terraform-proxmox-provider-variables) 27 | - [MAAS](#maas) 28 | 29 | ## Proxmox-VE 30 | 31 | It is an open source **Server Virtualization Platform**. [Proxmox-VE][Proxmox-VE] includes two different virtualization technologies which are **Kernel-Based Virtual Machine *(KVM)*** and **Container-Based Virtualization *(LXC)***. *Proxmox-VE* can run on a **single node**, or **assemble a cluster of many nodes**. This way, your virtual machines and containers can run on Proxmox-VE with high availability. 32 | 33 |
34 | Proxmox-VE Architecture 35 |
36 | 37 | ### Installation - Manual Step 38 | 39 | - Download the installer *ISO image* from: [Proxmox-VE ISO Image][PVE-ISO] 40 | - Create an *USB flash drive* and *Boot from USB* 41 | - [baleneEtcher][Etcher] is an easy way to create Proxmox-VE USB flash drive. 42 | 43 | | Installing Proxmox VE | | 44 | | :-------------------- | :--- | 45 | | *The Proxmox VE* menu will be displayed and select **Install Proxmox VE** to starts the normal installation.
[Click for more detail about Options][PVE-Installation] | ![Proxmox-VE Menu](./img/pve-menu-1.png) | 46 | | After selecting **Install Proxmox VE** and *accepting* **the EULA**, the prompt to select **the target hard disk(s)** will appear. The **Options** button opens the dialog to select the target file system. In my instruction, we can select the *default file system **ext4***, or **xfs** different from the one in the screenshot.
The installer creates a *Volume Group **(VG)*** called **pve**, and additional *Logical Volumes **(LVs)*** called **root**, **data**, and **swap**. To control the size of these volumes use:

[Click for more detail about Advanced LVM Options][PVE-LVM_Options] | ![Proxmox-VE Select Target Disk](./img/pve-menu-2-select-target-disk.png) | 47 | | After setting the disk options the next page asks for basic configuration options like the **location**, the **time zone**, and **keyboard** layout. *They only need to be changed in the rare case that **auto detection** fails or a **different keyboard layout** should be used.* | ![Proxmox-VE Select Location](./img/pve-menu-3-select-location.png) | 48 | | Next the *password* of the **superuser *(root)*** and an ***email*** address needs to be specified. The password must be at least **5** characters. However, it is highly recommended that you use a stronger password, so set a password that is at least **12 to 14** characters. The email address is used to send notifications to the system administrator. | ![Proxmox-VE Set Password](./img/pve-menu-4-set-password.png) | 49 | | The last step is the network configuration. Please note that during installation you can either use an IPv4 or IPv6 address, but not both. To configure a dual stack node, add additional IP addresses after the installation. *There will be created a proxmox cluster consisting of 3 physical servers. Therefore, 3 different network information is given below.* | ![Proxmox-VE Setup Network](./img/pve-menu-5-setup-network.png) | 50 | | The next step shows a summary of the previously selected options. Re-check every setting and use the **Previous** button if a setting needs to be changed. To accept, press **Install**. The installation starts to format disks and copies packages to the target. Please wait until this step has finished; then **remove** the installation medium and **restart** your system.
Then point your browser to the IP address given during installation ***`https://youripaddress:8006`*** to reach **Proxmox Web Interface**.
Default login is **"root"** and the **root password** is defined(step 4) during the installation process. | ![Proxmox-VE Installation Summary](./img/pve-menu-6-install-summary.png) | 51 | 52 | - After the installation is completed, the files which repositories are defined should be as follows in order to use APT Package Management tool successfully. 53 | - File /etc/apt/sources.list 54 | - `deb http://ftp.debian.org/debian buster main contrib` 55 | - `deb http://ftp.debian.org/debian buster-updates main contrib` 56 | - `deb http://security.debian.org/debian-security buster/updates main contrib` 57 | - `deb http://download.proxmox.com/debian/pve buster pve-no-subscription` 58 | - **Note:** PVE ***pve-no-subscription*** repository provided by *proxmox.com*, but NOT recommended for production use 59 | - File /etc/apt/sources.list.d/pve-enterprise.list 60 | - `#deb https://enterprise.proxmox.com/debian/pve buster pve-enterprise` 61 | - Then check `locale` if there is an error like "Cannot set LC_ALL(or others) to default locale: No such file or directory" 62 | - Run the following commands for each error 63 | - `echo "export LC_CTYPE=en_US.UTF-8" >> ~/.bashrc` 64 | - `echo "export LC_ALL=en_US.UTF-8" >> ~/.bashrc` 65 | - `source ~/.bashrc` 66 | - then run the following commands once 67 | - `locale-gen en_US en_US.UTF-8` 68 | - `dpkg-reconfigure locales` choose en_US.UTF-8 69 | - Get latest updates 70 | - `apt update && apt upgrade -y && apt dist-upgrade` 71 | - **RESTART/REBOOT** System 72 | - For more information to [Create Proxmox-VE Cluster][Create Proxmox-VE Cluster] 73 | 74 | --- 75 | 76 | ### Creating Ubuntu Image 77 | 78 | **Ubuntu ISO images** can be downloaded from [releases of Ubuntu][releases of Ubuntu]. For ***popular architectures***, please use ***releases of Ubuntu***. Also ***other Ubuntu images*** not found on releases of Ubuntu, such as builds for less popular architectures and other non-standard and unsupported images and daily build images, can downloaded from [the cdimage server][the cdimage server]. For old releases, see [old-releases of Ubuntu][old-releases of Ubuntu]. 79 | 80 | As of the Ubuntu LTS release in 2020, **the server documentation** has moved to [Ubuntu Server Guide][Ubuntu Server Guide]. However; the detailed **ubuntu latest LTS *installation guide*** can be found [here][Ubuntu Installation Guide]. 81 | 82 | Fully automated installations are possible on Ubuntu using [Ubuntu Installer(debian-installer)][Ubuntu Installer(debian-installer)] or [Ubuntu Live Server Installer(autoinstall)][Ubuntu Live Server Installer(autoinstall)]. 83 | 84 | - The Ubuntu Installer (based on the Debian Installer, and so often called simply **debian-installer** or just **d-i)** consists of a number of special-purpose components to perform each installation task. The debian-installer(*d-i)*) supports automating installs via **preconfiguration(*preseed.cfg*) files**. Preseeding method provides a way to set answers to questions asked during the installation process, without having to manually enter the answers while the installation is running. For more information visit [Automating the Installation using Preseeding][Automating the Installation using Preseeding], [Example Preseed File][Example Preseed File] and [Packer Preseed Ubuntu][Packer Preseed Ubuntu]. 85 | - However, Ubuntu [announced][Server installer plans for 20.04 LTS] that it will complete the transition to **the Live Server Installer**(*autoinstall)* with 20.04 LTS. It lets you answer all those configuration questions ahead of time with an ***autoinstall config*** and lets the installation process run without any interaction. The *autoinstall config* is provided via [cloud-init configuration][Cloud-Init-Config Documentation], which is almost endlessly flexible. [The live server installer is now the preferred media to install](https://wiki.ubuntu.com/FocalFossa/ReleaseNotes#Installer) Ubuntu Server on all architectures. For more information visit [Ubuntu Autoinstall Quick Start][Ubuntu Autoinstall Quick Start] and [Automated Server Installs Config File Reference][Automated Server Installs Config File Reference] 86 | 87 | Ubuntu also offers ***Cloud Images***. [Ubuntu Cloud Images][Ubuntu Cloud Images] are the *official Ubuntu images* and are *pre-installed disk images* that have been customized by ***Ubuntu engineering to run on public clouds that provide Ubuntu Certified Images, Openstack, LXD, and more***. It will be used in [`create-template-via-cloudinit.sh`](#installation---script-step---creating-cloud-init-template) due to the **fast** and **easy** setup. 88 | 89 |
90 | To create Ubuntu Images via ISO without using Cloud-Images, the following repositories and articles can be viewed 91 | 92 | - [Automating Ubuntu 20.04 installs with Packer][Automating Ubuntu 20.04 installs with Packer] 93 | - [Automating Ubuntu Server 20.04 with Packer][Automating Ubuntu Server 20.04 with Packer] 94 | - [Packer build - Ubuntu Images(autoinstall & cloud-config)][Packer build - Ubuntu Images(autoinstall & cloud-config)] 95 | - [Packer Ubuntu 20.04 Image(autoinstall & cloud-config)][Packer Ubuntu 20.04 Image(autoinstall & cloud-config)] 96 | - [Madalynn Packer - Ubuntu Image(autoinstall & cloud-config)][Madalynn Packer - Ubuntu Image(autoinstall & cloud-config)] 97 | - [Packer Proxmox Ubuntu Templates(ansible & preseed)][Packer Proxmox Ubuntu Templates(ansible & preseed)] 98 | - [Packer Boxes(ansible & preseed)][Packer Boxes(ansible & preseed)] 99 | - [Packer Proxmox Ubuntu Templates(preseed)][Packer Proxmox Ubuntu Templates(preseed)] 100 | - [Packer Ubuntu Templates(preseed)][Packer Ubuntu Templates(preseed)] 101 | - [Packer Templates for Ubuntu(preseed)][Packer Templates for Ubuntu(preseed)] 102 | - [Automated image builds with Jenkins, Packer, and Kubernetes][Automated image builds with Jenkins, Packer, and Kubernetes] 103 | 104 |
105 | 106 | --- 107 | 108 |
109 | Creating Ubuntu Image Documents 110 | 111 | - **Install Ubuntu ISO images** 112 | - [releases of Ubuntu][releases of Ubuntu] 113 | - [the cdimage server][the cdimage server] 114 | - [old-releases of Ubuntu][old-releases of Ubuntu] 115 | - [Ubuntu Server Guide][Ubuntu Server Guide] 116 | - [Ubuntu Installer(debian-installer)][Ubuntu Installer(debian-installer)] 117 | - [Ubuntu Live Server Installer(autoinstall)][Ubuntu Live Server Installer(autoinstall)] 118 | - [Automating the Installation using Preseeding][Automating the Installation using Preseeding] 119 | - [Example Preseed File][Example Preseed File] 120 | - [Packer Preseed Ubuntu][Packer Preseed Ubuntu] 121 | - [Server installer plans for 20.04 LTS][Server installer plans for 20.04 LTS] 122 | - [Ubuntu Autoinstall Quick Start][Ubuntu Autoinstall Quick Start] 123 | - [Automated Server Installs Config File Reference][Automated Server Installs Config File Reference] 124 | - [Ubuntu Cloud Images][Ubuntu Cloud Images] 125 | - [Ubuntu Enterprise Cloud - Images][Ubuntu Enterprise Cloud - Images] 126 | 127 |
128 | 129 | --- 130 | 131 | ### Installation - Script Step - Creating cloud-init Template 132 | 133 | After installation to create cloud-init template(s) `create-template-via-cloudinit.sh` should be executed on Proxmox-VE Server(s). The script is based on the [create-cloud-template.sh][chriswayg-gist] developed by [chriswayg][chriswayg]. 134 | 135 | | | `create-template-via-cloudinit.sh` Execution Prerequisites | 136 | | :-: | :--------------------------------------------------------- | 137 | | 1 |`create-template-via-cloudinit.sh` **must be executed on a Proxmox VE 6.x Server.** | 138 | | 2 |A DHCP Server should be active on `vmbr0`. | 139 | | 3 | **Download Latest Version of the Script on Proxmox VE Server:**
`curl https://raw.githubusercontent.com/BarisGece/mHC/main/proxmox-ve/create-template-via-cloudinit.sh > /usr/local/bin/create-template-via-cloudinit.sh && chmod -v +x /usr/local/bin/create-template-via-cloudinit.sh` | 140 | | 4 | **-- Caution! MUST BE DONE to USE cloud-init-config.yml --**
The cloud-init files need to be stored in a **snippet**. There is not detail information very well documented in [Proxmox-VE qm cloud_init][Proxomox-VE qm cloud_init] but [Alex Williams][AW Gist] kept us well informed.
  1. Go to `Storage View -> Storage -> Add -> Directory`
  2. Give it an ID such as `snippets`, and specify any path on your host such as `/snippets`
  3. Under `Content` choose `Snippets` and de-select `Disk image` (optional)
  4. Upload (scp/rsync/whatever) your `user-data, meta-data, network-config` files to your _proxmox_ server in `/snippets/snippets/` (the directory should be there if you followed steps 1-3)
Finally, you just need to `qm set` with `--cicustom`, like this:(If `cloud-init-config.yml` is present, the following command will run automatically in `create-template-via-cloudinit.sh`)
`qm set 100 --cicustom "user=snippets:snippets/user-data,network=snippets:snippets/network-config,meta=snippets:snippets/meta-data"` | 141 | | 5 | Prepare a cloudinit **user-cloud-init-config.yml** in the working directory. [sample-cloud-init-config.yml][sample-cloud-init-config.yml] can be used as a sample.
For more information [Cloud-Init-Config Sample][Cloud-Init-Config Sample]. | 142 | | 6 | To the migration to be completed successfully, the Proxmox Storage Configuration should be set as follows.
**local**(*Type - Directory*): **local-lvm**(*Type - LVM-Thin*): **snippets**(*Type - Directory*): *All of them should be **ENABLED***
![DC_Storage_Settings](./img/DC_Storage_Settings.png) | 143 | | 7 | Run the Script:
`$ create-template-via-cloudinit.sh` | 144 | | 8 | Clone the Finished Template from the Proxmox GUI and Test. | 145 | 146 | --- 147 | 148 | ### For Maximum Performance 149 | 150 | - **Network Device** 151 | - The **VirtIO paravirtualized NIC** should be used if you aim for **maximum performance**. Like all VirtIO devices, the guest OS should have the proper driver installed. 152 | - The **VirtIO model** provides the ***best performance*** with very **low CPU overhead**. If your guest does not support this driver, it is usually best to **use e1000**. 153 | - `qm create 9000 --memory 2048 --net0 virtio,bridge=vmbr0` 154 | - **Hard Disk -- Bus/Controller -- Cache** 155 | - If you aim at **maximum performance**, you can select a **SCSI** controller of type **VirtIO SCSI single** which will allow you to select the IO Thread option. 156 | - **cache=none** seems to be the best performance and is the default since Proxmox 2.X. However, **cache=unsafe** doesn't flush data, so it's ***fastest*** but ***unsafest***. The information is based on using **raw volumes**, other volume formats may behave differently. For more information [Performance Tweaks][Performance Tweaks]. 157 | - Use **raw disk** image instead of **qcow2** if possible 158 | - `qm importdisk 9000 /tmp/VMIMAGE local-lvm --format raw` 159 | - `qm set 9000 --scsihw virtio-scsi-single --scsi0 local-lvm:vm-9000-disk-0,iothread=1` 160 | - **CPU Types** 161 | - If you have a ***homogeneous cluster where all nodes have the same CPU***, set the **CPU type** to **host**, as in theory this will give your guests maximum performance. 162 | - `qm set 9000 --cpu host` 163 | - **NUMA(*non-uniform memory access*)** 164 | - With NUMA, **memory** can be evenly *distributed among CPUs*, which improves performance. Also, to enable **CPU** and **Memory** *hot-plugging* in Proxmox-VE, *NUMA* option should be *enabled*. To enable NUMA option on VM execute the following **command**. 165 | - `qm set --kvm 1 numa 1` 166 | - If the following **command** returns ***more than one node***, then your host system has a **NUMA** architecture. 167 | - `numactl --hardware | grep available` 168 | - `numactl --hardware` 169 | - This command will show all the nodes in the cluster that are NUMA aware and their performance stats. 170 | - `numastat` 171 | - **HOT-PLUGGING** 172 | - The **hotplugging** feature provides the ability to **add** or **remove** devices or resources from the Virtual Machine ***without rebooting***. To enable **hotplug** execute the following **command**. 173 | - qm set --hotplug disk,network,usb,memory,cpu 174 | - **NUMA** option **MUST be ENABLED**. 175 | - ***Preparing Linux Guests*** 176 | - A kernel newer than **4.7** is recommended for Linux Guests for all hotplugging features to work. 177 | - The following **kernel modules should bu installed** on **Linux Guests**. To automatically load the modules during boot, add them into **`/etc/modules`**. The automate command was added to `sample-cloud-init-config.yml`
Caution! Lines beginning with "#" are ignored. 178 | - `# modprobe acpiphp`
`# modprobe pci_hotplug` 179 | - After kernel **4.7**, ***only*** the following kernel parameter should be added to `/etc/default/grub` ***during boot*** for the **CPU**. It also added to `sample-cloud-init-config.yml`. 180 | - `GRUB_CMDLINE_LINUX_DEFAULT="quiet splash memhp_default_state=online"` 181 | - Update the **grub boot loader** 182 | - `sudo update-grub` 183 | - **REBOOT Linux Guest** 184 | - Sample command for **hotplugging vCPUs** 185 | - In Proxmox VE the ***maximal number of plugged vCPUs*** is always `cores * sockets`. Also, `Total Cores = cores * sockets`. ***vCPUs value*** can not more than ***Total Core*** 186 | - `qm set 9000 -vcpus 4` 187 | - | Device | Kernel | Hotplug | Unplug | OS | 188 | | :----: | :----: | :-----------: | :-----------: | :------------------------: | 189 | | Disk | All | Linux/Windows | Linux/Windows | Linux/Windows | 190 | | NIC | All | Linux/Windows | Linux/Windows | Linux/Windows | 191 | | USB | All | Linux/Windows | Linux/Windows | Linux/Windows | 192 | | CPU | 3.10+ | Linux/Windows | Linux(4.10+) | Linux/Windows Server 2008+ | 193 | | Memory | 3.10+ | Linux/Windows | Linux(4.10+) | Linux/Windows Server 2008+ | 194 | - **Ballooning Device** 195 | - Amount of target RAM for the VM in MB. Using zero disables the ballon driver. In general, you should leave **ballooning** ***enabled***, but if you want to disable it (e.g. for debugging purposes), simply ***uncheck*** **Ballooning Device** or set `balloon: 0` in the ***configuration***. 196 | - Even when using a fixed memory size, the ballooning device gets added to the VM, because it delivers useful information such as how much memory the guest really uses. 197 | - All Linux distributions released after **2010** have the ***balloon kernel driver included***. For Windows OSes, the balloon driver needs to be added manually and can incur a slowdown of the guest, so we don’t recommend using it on critical systems. The passing around of memory between host and guest is done via a special balloon kernel driver running inside the guest, which will grab or release memory pages from the host. A good explanation of the inner workings of the balloon driver can be found [here][Virtio Balloon] 198 | 199 | --- 200 | 201 | ### Create PVE User for Terraform, Packer & Ansible 202 | 203 | `create-proxmox-users.sh` will create Proxmox users for *Packer*, *Terraform* and *Ansible*. The password information of the users to be created will be read from *Environment Variables*. Before running the script, define the variables with the following *Environment Variable Names*. For more information [pveum User Management][pveum User Management] 204 | 205 | - `$PACKER_PVE_USER`, `$PACKER_PVE_PASSWORD` - `$TERRAFORM_PVE_USER`, `$TERRAFORM_PVE_PASSWORD` - `$ANSIBLE_PVE_USER`, `$ANSIBLE_PVE_PASSWORD` 206 | - `create-proxmox-users.sh` **must be executed *once* on a Proxmox VE 6.x Server.** 207 | - `curl https://raw.githubusercontent.com/BarisGece/mHC/main/proxmox-ve/create-proxmox-users.sh > /usr/local/bin/create-proxmox-users.sh && chmod -v +x /usr/local/bin/create-proxmox-users.sh` 208 | 209 | --- 210 | 211 |
212 | Proxmox-VE Documents 213 | 214 | - [Admin Guide - PDF][Admin Guide - PDF] 215 | - [Admin Guide - HTML][Admin Guide - HTML] 216 | - [Wiki Page][Wiki Page] 217 | - [Qemu/KVM(qm) Virtual Machines-Guide][Qemu/KVM(qm) Virtual Machines-Guide] 218 | - [Qemu/KVM(qm) VM Templates-Wiki][Qemu/KVM(qm) VM Templates-Wiki] 219 | - [Proxomox-VE qm Commands][Proxomox-VE qm Command Line Interface] 220 | - [Proxmox(qm) Cloud-Init Support-Guide][Proxmox(qm) Cloud-Init Support-Guide] 221 | - [Proxmox(qm) Cloud-Init Support-Wiki][Proxmox(qm) Cloud-Init Support-Wiki] 222 | - [Proxmox(qm) Cloud-Init Support FAQ-Wiki][Proxmox(qm) Cloud-Init Support FAQ-Wiki] 223 | - [Canonical cloud-init][Canonical cloud-init] 224 | - [Cloud-Init-Config Sample][Cloud-Init-Config Sample] 225 | - [Cloud-Init-Config Documentation][Cloud-Init-Config Documentation] 226 | - [Performance Tweaks][Performance Tweaks] 227 | - [Virtio Balloon][Virtio Balloon] 228 | - [NUMA][NUMA] 229 | - [Hotplug][Hotplug] 230 | - [pveum User Management][pveum User Management] 231 | - [Ansible role to configure Proxmox server][Ansible role to configure Proxmox server] 232 | - [Provision Proxmox VMs with Ansible, quick and easy][Provision Proxmox VMs with Ansible, quick and easy] 233 | 234 |
235 | 236 | --- 237 | 238 | ## Packer 239 | 240 | Packer is an **automatic machine image generation** tool and ***Proxmox-VE templates*** will be created with ***Packer*** to make it more standardized and automated. 241 | 242 | ### Installing Packer on Ubuntu Jump Server 243 | 244 | - Add the HashiCorp GPG key. 245 | - `curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -` 246 | - Add the official HashiCorp Linux repository. 247 | - `sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"` 248 | - Update and install. 249 | - `sudo apt-get update && sudo apt-get install packer` 250 | 251 | ### Preparing Proxmox-VE template via Packer 252 | 253 | [Packer Proxmox Builder][Packer Proxmox Builder] will be used to create the *Proxmox-VE template*. It provision and configure the VM and then converts it into a template. *Packer Proxmox Builder* perfoms operations via the [Proxmox Web API][Proxmox Web API]. 254 | 255 | Packer Proxmox Builder is able to create new images using both **ISO**([proxmox-iso][proxmox-iso]) and existing **Cloud-Init Images**([proxmox-clone][proxmox-clone]). Creating a new image using ([proxmox-iso][proxmox-iso]) will be developed later. 256 | 257 | Now, **Proxmox-VE templates** will be created with **proxmox-clone** using **existing Cloud-Init Images** created via `create-template-via-cloudinit.sh`. 258 | 259 | | | Packer Execution Prerequisites | 260 | | :-: | :----------------------------- | 261 | | 1 |To skip validating the certificate set `insecure_skip_tls_verify = true` in **sources.pkr.hcl** | 262 | | 2 |To Packer run sucessfully `qemu-guest-agent` must be installed on VMs & `qemu_agent = ...` configuration option should be `true` in `sources.pkr.hcl`
For more detail [Error getting SSH address 500 QEMU guest agent is not running][QEMU Agent Error-Github]| 263 | 264 | #### Input Variables 265 | 266 | In Packer, ***Assigning Values* to the build Variables** with *HCL2* can be done in **3** different ways as follows 267 | 268 | - **Command-line flags** 269 | - Variables can be defined directly on the *command line* with the `-var` flag. We will not use. 270 | - `packer build -var 'weekday=Sunday' -var 'flavor=chocolate'` 271 | - **Variables file** 272 | - To persist variable values, create a `*.pkrvars.hcl` file and assign variables within this file. Also, packer will **automatically load any var file** that matches the name `*.auto.pkrvars.hcl`, without the need to pass the file via the command line. 273 | - `*.pkrvars.hcl` => `packer build -var-file="*.pkrvars.hcl" .` 274 | - `*.auto.pkrvars.hcl` => `packer build .` 275 | - **Environment Variables** 276 | - Packer will read ***environment variables*** in the form of `PKR_VAR_name` to find the value for a variable. 277 | - `export PKR_VAR_access_key=Key1 && packer build .` 278 | - **Variable Defaults** 279 | - If no value is assigned to a variable via any of these methods and the variable has a `default` key in its declaration, that value will be used for the variable. 280 | - `packer build .` 281 | - **Notes about Packer Variables** 282 | - Don't save **sensitive data** to version control via *varibles files*. You can create a **local secret variables file** or use **environment variables** 283 | - **Multiple** `-var-file` flags can be provided.
`packer build -var-file="secret.pkrvars.hcl" -var-file="production.pkrvars.hcl" .` 284 | - If a **default value** is set in `variables.pkr.hcl`, the *variable is optional*. Otherwise, the *variable must be set*. To force set variables don't set **default value** as `variable "vm_id" {...}` in `variables.pkr.hcl` 285 | - The `variable` block, also called the `input-variable` block, defines variables within your *Packer* configuration. 286 | - **Debug** => `PACKER_LOG=1 packer build -debug -on-error=ask .`
**Release** => `PACKER_LOG=1 packer build .` 287 | 288 | #### `local` Variables 289 | 290 | An `input-variable` cannot be used in **another input variable**, so [locals][The locals block] could be used instead. The `locals` **block**, also called the `local-variable` **block**, defines locals within your Packer configuration. [Local Values][Local Values] assign a name to an expression, that can then be used multiple times within a folder. 291 | 292 | ```sh 293 | # locals.pkr.hcl 294 | locals { 295 | # locals can be bare values like: 296 | wee = local.baz 297 | # locals can also be set with other variables : 298 | baz = "Foo is '${var.foo}' but not '${local.wee}'" 299 | } 300 | ``` 301 | 302 |
303 | Packer Documents 304 | 305 | - [Packer Proxmox Builder][Packer Proxmox Builder] 306 | - [proxmox-clone][proxmox-clone] **&** [proxmox-iso][proxmox-iso] 307 | - [Input Variables and `local` variables][Input Variables and local variables] 308 | - [The `variable` block][The variable block] 309 | - [Input Variables][Input Variables] 310 | - [The `locals` block][The locals block] 311 | - [Local Values][Local Values] 312 | - [Creating Proxmox Templates with Packer - Aaron Berry][Aaron Berry Packer Article] 313 | - [Article Github Repo][Aaron Berry Article Repo] 314 | 315 |
316 | 317 | --- 318 | 319 | ## Terraform 320 | 321 | [Terraform][Terraform] is an **Infrastructure as Code** tool to securely and efficiently provision, manage, and version infrastructure. Having more than **1000** [Modules][Terraform Modules] and more than **200** [Providers][Terraform Providers] makes it easy to manage existing and popular infrastructure, cloud or service providers as well as *custom on-premises solutions*. 322 | 323 | The operations on ***Proxmox-VE*** are performed over ***Proxmox Web API*** as in the *Packer*. There is ***no officially supported* Proxmox Provider** on Terraform, but there are two **Community-Supported Providers** as below. 324 | 325 | - [Telmate - Terraform Proxmox Provider][Telmate - Terraform Proxmox Provider] 326 | - [Danitso - Terraform Proxmox Provider][Danitso - Terraform Proxmox Provider] 327 | 328 | ### Installing Terraform on Ubuntu Jump Server 329 | 330 | - Add the HashiCorp GPG key. 331 | - `curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -` 332 | - Add the official HashiCorp Linux repository. 333 | - `sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"` 334 | - Update and install. 335 | - `sudo apt-get update && sudo apt-get install terraform` 336 | 337 | ### Provisioning Virtual Machine on Proxmox-VE via Terraform 338 | 339 | **Terraform Proxmox Provider** can create **Virtual Machines(*Instances, Guest OS*)** via an **ISO** or **CLONE(*existing images*)** such as *Packer Proxmox Builder*. Cloud-init defined Proxmox-VE templates were created by `create-template-via-cloudinit.sh` & `packer_proxmox-clone`. New instances will be created using these templates. The Terraform can be found [here](./terraform). 340 | 341 | #### Terraform Input Variables 342 | 343 | The same variable cannot be assigned multiple values ​​within a single resource, so variables are loaded in the following order and subsequent resources override previous values. 344 | 345 | - **Environment variables** 346 | - The `terraform.tfvars` file 347 | - The `terraform.tfvars.json` file 348 | - Any `*.auto.tfvars` or `*.auto.tfvars.json` files, *execution order is by file names* 349 | - Any `-var` and `-var-file` options on the command line, *in the order they are provided* 350 | 351 | #### Terraform Proxmox Provider Variables 352 | 353 | - `pm_api_url` is **required**. If `var.api_url` is not set, `PM_API_URL` must be set as the ***environment variable***. 354 | - `pm_user` is **required**. If `var.user` is not set, `PM_USER` must be set as the ***environment variable***. 355 | - `pm_password` is required. If `var.password` is not set, `PM_PASS` must be set as the ***environment variable***. One of the recommended ways to set up `PM_PASS` 356 | - If the **2FA OTP code** is to be used, `var.otp` must be defined. If `var.otp` is not defined, `PM_OTP` must be set as the ***environment variable***. `PM_OTP` must be set as the ***environment variable***. Also, `PM_OTP_PROMPT` can be set as ***environment variable*** to ask for ***OTP 2FA code***. 357 | - Either `clone` or `iso` **must be set** in ***resource block variables***. If both are set, the `clone` will be accepted. Therefore; ***only set one of them*** and the value of the other should be `null`. 358 | - Sample for **ISO**: Using an iso file uploaded on the local storage = `local:iso/proxmox-mailgateway_2.1.iso` 359 | - Sample for **CLONE**: The name of the Proxmox-VE template or image to be used to provision the new VM = `ubuntu2004-cloud-template`. 360 | - `full_clone`: The result of such copy is an independent VM. The new VM does not share any storage resources with the original. Default value is `true`. However; a full clone needs to read and copy all VM image data. This is usually much slower than creating a linked clone. 361 | 362 | --- 363 | 364 |
365 | Terraform Documents 366 | 367 | - [Terraform Introduction][Terraform Introduction] 368 | - [Terraform Documentation][Terraform Documentation] 369 | - [Telmate - Provider Block Arguments][Telmate - Provider Block Arguments] 370 | - [Telmate - VM Qemu Resource][Telmate - VM Qemu Resource] 371 | - [Telmate - Cloud Init Guide][Telmate - Cloud Init Guide] 372 | 373 |
374 | 375 | --- 376 | 377 | ## MAAS 378 | 379 | [MAAS][MAAS] is a **Metal as a Service** that allows you to treat physical servers in the Cloud like VM Instances. It turns bare metal into a flexible cloud-like resource, so there is no need to manage servers individually. For more information [MAAS Docs][MAAS Docs] **&** [Proxmox - MAAS - JuJu by VectOps][Proxmox - MAAS - JuJu by VectOps] 380 | 381 | [Proxmox-VE]: https://www.proxmox.com/ 382 | [PVE-ISO]: https://www.proxmox.com/en/downloads/category/iso-images-pve 383 | [Etcher]: https://www.balena.io/etcher/ 384 | [PVE-Installation]: https://pve.proxmox.com/pve-docs/pve-admin-guide.html#chapter_installation 385 | [PVE-LVM_Options]: https://pve.proxmox.com/pve-docs/pve-admin-guide.html#advanced_lvm_options 386 | [Create Proxmox-VE Cluster]: https://pve.proxmox.com/pve-docs/pve-admin-guide.html#pvecm_create_cluster 387 | [releases of Ubuntu]: https://releases.ubuntu.com/ 388 | [the cdimage server]: https://cdimage.ubuntu.com/ 389 | [old-releases of Ubuntu]: https://old-releases.ubuntu.com/ 390 | [Ubuntu Server Guide]: https://ubuntu.com/server/docs 391 | [Ubuntu Installation Guide]: https://help.ubuntu.com/lts/installation-guide 392 | [Ubuntu Installer(debian-installer)]: https://help.ubuntu.com/lts/installation-guide/amd64/ch06s01.html 393 | [Ubuntu Live Server Installer(autoinstall)]: https://ubuntu.com/server/docs/install/autoinstall 394 | [Automating the Installation using Preseeding]: https://help.ubuntu.com/lts/installation-guide/amd64/apb.html 395 | [Example Preseed File]: https://help.ubuntu.com/lts/installation-guide/example-preseed.txt 396 | [Packer Preseed Ubuntu]: https://www.packer.io/guides/automatic-operating-system-installs/preseed_ubuntu.html 397 | [Server installer plans for 20.04 LTS]: https://discourse.ubuntu.com/t/server-installer-plans-for-20-04-lts/13631 398 | [Canonical cloud-init]: https://cloud-init.io/ 399 | [Cloud-Init-Config Documentation]: https://cloudinit.readthedocs.io/en/latest/ 400 | [Ubuntu Autoinstall Quick Start]: https://ubuntu.com/server/docs/install/autoinstall-quickstart 401 | [Automated Server Installs Config File Reference]: https://ubuntu.com/server/docs/install/autoinstall-reference 402 | [Ubuntu Cloud Images]: https://cloud-images.ubuntu.com/ 403 | [Ubuntu Enterprise Cloud - Images]: https://help.ubuntu.com/community/UEC/Images 404 | [Automating Ubuntu 20.04 installs with Packer]: https://nickcharlton.net/posts/automating-ubuntu-2004-installs-with-packer.html 405 | [Automating Ubuntu Server 20.04 with Packer]: https://beryju.org/blog/automating-ubuntu-server-20-04-with-packer 406 | [Packer build - Ubuntu Images(autoinstall & cloud-config)]: https://github.com/tylert/packer-build 407 | [Packer Ubuntu 20.04 Image(autoinstall & cloud-config)]: https://github.com/nickcharlton/packer-ubuntu-2004 408 | [Madalynn Packer - Ubuntu Image(autoinstall & cloud-config)]: https://github.com/aerialls/madalynn-packer 409 | [Packer Proxmox Ubuntu Templates(ansible & preseed)]: https://github.com/chriswayg/packer-proxmox-templates 410 | [Packer Boxes(ansible & preseed)]: https://github.com/geerlingguy/packer-boxes/blob/master/ubuntu2004/box-config.json 411 | [Packer Proxmox Ubuntu Templates(preseed)]: https://github.com/Aaron-K-T-Berry/packer-ubuntu-proxmox-template 412 | [Packer Ubuntu Templates(preseed)]: https://github.com/chef/bento/tree/master/packer_templates/ubuntu 413 | [Packer Templates for Ubuntu(preseed)]: https://github.com/boxcutter/ubuntu 414 | [Automated image builds with Jenkins, Packer, and Kubernetes]: https://cloud.google.com/solutions/automated-build-images-with-jenkins-kubernetes 415 | [chriswayg]: https://github.com/chriswayg 416 | [chriswayg-gist]: https://gist.github.com/chriswayg/43fbea910e024cbe608d7dcb12cb8466 417 | [Proxomox-VE qm cloud_init]: https://pve.proxmox.com/pve-docs/pve-admin-guide.html#qm_cloud_init 418 | [AW Gist]: https://gist.github.com/aw/ce460c2100163c38734a83e09ac0439a 419 | [sample-cloud-init-config.yml]: https://raw.githubusercontent.com/BarisGece/mHC/main/proxmox-ve/sample-cloud-init-config.yml 420 | [Cloud-Init-Config Sample]: https://cloudinit.readthedocs.io/en/latest/topics/examples.html#yaml-examples 421 | [Admin Guide - PDF]: https://proxmox.com/en/downloads/item/proxmox-ve-admin-guide-for-6-x 422 | [Admin Guide - HTML]: https://pve.proxmox.com/pve-docs/pve-admin-guide.html 423 | [Wiki Page]: https://pve.proxmox.com/wiki/Main_Page 424 | [Qemu/KVM(qm) Virtual Machines-Guide]: https://pve.proxmox.com/pve-docs/pve-admin-guide.html#chapter_virtual_machines 425 | [Qemu/KVM(qm) VM Templates-Wiki]: https://pve.proxmox.com/wiki/Qemu/KVM_Virtual_Machines#qm_templates 426 | [Proxomox-VE qm Command Line Interface]: https://pve.proxmox.com/pve-docs/qm.1.html 427 | [Proxmox(qm) Cloud-Init Support-Guide]: https://pve.proxmox.com/pve-docs/pve-admin-guide.html#qm_cloud_init 428 | [Proxmox(qm) Cloud-Init Support-Wiki]: https://pve.proxmox.com/wiki/Cloud-Init_Support 429 | [Proxmox(qm) Cloud-Init Support FAQ-Wiki]: https://pve.proxmox.com/wiki/Cloud-Init_FAQ 430 | [Performance Tweaks]: https://pve.proxmox.com/wiki/Performance_Tweaks 431 | [Virtio Balloon]: https://rwmj.wordpress.com/2010/07/17/virtio-balloon/ 432 | [NUMA]: https://pve.proxmox.com/wiki/NUMA 433 | [Hotplug]: https://pve.proxmox.com/wiki/Hotplug_(qemu_disk,nic,cpu,memory) 434 | [pveum User Management]: https://pve.proxmox.com/pve-docs/chapter-pveum.html 435 | [Ansible role to configure Proxmox server]: https://github.com/chriswayg/ansible-proxmox 436 | [Provision Proxmox VMs with Ansible, quick and easy]: https://vectops.com/2020/01/provision-proxmox-vms-with-ansible-quick-and-easy/.packer.io/docs/builders/proxmox.html 437 | [Proxmox Web API]: https://pve.proxmox.com/wiki/Proxmox_VE_API 438 | [proxmox-clone]: https://www.packer.io/docs/builders/proxmox/clone 439 | [proxmox-iso]: https://www.packer.io/docs/builders/proxmox/iso 440 | [QEMU Agent Error-Github ]: https://github.com/hashicorp/packer/issues/9539#issuecomment-728378170 441 | [The locals block]: https://www.packer.io/docs/from-1.5/blocks/locals 442 | [Local Values]: https://www.packer.io/docs/from-1.5/locals 443 | [Input Variables and local variables]: https://www.packer.io/guides/hcl/variables 444 | [The variable block]: https://www.packer.io/docs/from-1.5/blocks/variable 445 | [Input Variables]: https://www.packer.io/docs/from-1.5/variables 446 | [Aaron Berry Packer Article]: https://dev.to/aaronktberry/creating-proxmox-templates-with-packer-1b35 447 | [Aaron Berry Article Repo]: https://github.com/Aaron-K-T-Berry/packer-ubuntu-proxmox-template 448 | [Terraform]: https://www.terraform.io/ 449 | [Terraform Modules]: https://registry.terraform.io/ 450 | [Terraform Providers]: https://www.terraform.io/docs/providers/ 451 | [Telmate - Terraform Proxmox Provider]: https://github.com/Telmate/terraform-provider-proxmox 452 | [Danitso - Terraform Proxmox Provider]: https://github.com/danitso/terraform-provider-proxmox 453 | [Terraform Introduction]: https://www.terraform.io/intro/index.html 454 | [Terraform Documentation]: https://www.terraform.io/docs/index.html 455 | [Telmate - Provider Block Arguments]: https://github.com/Telmate/terraform-provider-proxmox/blob/master/docs/index.md 456 | [Telmate - VM Qemu Resource]: https://github.com/Telmate/terraform-provider-proxmox/blob/master/docs/resources/vm_qemu.md 457 | [Telmate - Cloud Init Guide]: https://github.com/Telmate/terraform-provider-proxmox/blob/master/docs/guides/cloud_init.md 458 | [MAAS]: https://maas.io/ 459 | [MAAS Docs]: https://maas.io/docs 460 | [Proxmox - MAAS - JuJu by VectOps]: https://vectops.com/2020/02/production-ready-kubernetes-paas-in-10-steps-iaas-included/ 461 | -------------------------------------------------------------------------------- /img/DC_Storage_Settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarisGece/mHC/c6a2ad679deb6baf097877b6b596b9876aad5f66/img/DC_Storage_Settings.png -------------------------------------------------------------------------------- /img/Proxmox-VE_Architecture.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | pve_software_stack 11 | 12 | 13 | stack 14 | 15 | User Tools 16 | 17 | 18 | qm 19 | 20 | pvesm 21 | 22 | pveum 23 | 24 | ha-manager 25 | 26 | pct 27 | 28 | pvecm 29 | 30 | pveceph 31 | 32 | pve-firewall 33 | 34 | Services 35 | 36 | 37 | pveproxy 38 | 39 | pvedaemon 40 | 41 | pvestatd 42 | 43 | pve-ha-lrm 44 | 45 | pve-cluster 46 | 47 | VM 48 | 49 | App 50 | 51 | App 52 | 53 | Guest OS 54 | 55 | VM 56 | 57 | App 58 | 59 | App 60 | 61 | Guest OS 62 | 63 | Qemu 64 | 65 | 66 | 67 | 68 | Container 69 | 70 | App 71 | 72 | App 73 | 74 | Container 75 | 76 | App 77 | 78 | App 79 | 80 | 81 | 82 | KVM 83 | Linux Kernel 84 | 85 | AppArmor 86 | 87 | cgroups 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /img/mHC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarisGece/mHC/c6a2ad679deb6baf097877b6b596b9876aad5f66/img/mHC.png -------------------------------------------------------------------------------- /img/pve-menu-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarisGece/mHC/c6a2ad679deb6baf097877b6b596b9876aad5f66/img/pve-menu-1.png -------------------------------------------------------------------------------- /img/pve-menu-2-select-target-disk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarisGece/mHC/c6a2ad679deb6baf097877b6b596b9876aad5f66/img/pve-menu-2-select-target-disk.png -------------------------------------------------------------------------------- /img/pve-menu-3-select-location.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarisGece/mHC/c6a2ad679deb6baf097877b6b596b9876aad5f66/img/pve-menu-3-select-location.png -------------------------------------------------------------------------------- /img/pve-menu-4-set-password.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarisGece/mHC/c6a2ad679deb6baf097877b6b596b9876aad5f66/img/pve-menu-4-set-password.png -------------------------------------------------------------------------------- /img/pve-menu-5-setup-network.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarisGece/mHC/c6a2ad679deb6baf097877b6b596b9876aad5f66/img/pve-menu-5-setup-network.png -------------------------------------------------------------------------------- /img/pve-menu-6-install-summary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarisGece/mHC/c6a2ad679deb6baf097877b6b596b9876aad5f66/img/pve-menu-6-install-summary.png -------------------------------------------------------------------------------- /packer/packer_proxmox-clone/build.pkr.hcl: -------------------------------------------------------------------------------- 1 | # Files need to be suffixed with '.pkr.hcl' to be visible to Packer. 2 | # To use multiple files at once they also need to be in the same folder. 3 | # 'packer inspect folder/' will describe to you what is in that folder. 4 | 5 | # a build block invokes sources and runs provisioning steps on them. The 6 | # documentation for build blocks can be found here: 7 | # https://www.packer.io/docs/from-1.5/blocks/build 8 | 9 | build { 10 | sources = ["sources.proxmox-clone.mhc"] 11 | } -------------------------------------------------------------------------------- /packer/packer_proxmox-clone/locals.pkr.hcl: -------------------------------------------------------------------------------- 1 | # Local Variables and Type Constraints 2 | # https://www.packer.io/guides/hcl/variables#defining-variables-and-locals 3 | # https://www.packer.io/docs/from-1.5/variables#type-constraints for more info. 4 | # "timestamp" template function replacement 5 | locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") } -------------------------------------------------------------------------------- /packer/packer_proxmox-clone/sources.pkr.hcl: -------------------------------------------------------------------------------- 1 | # Files need to be suffixed with '.pkr.hcl' to be visible to Packer. 2 | # To use multiple files at once they also need to be in the same folder. 3 | # 'packer inspect folder/' will describe to you what is in that folder. 4 | 5 | # source blocks are generated from your builders; a source can be referenced in 6 | # build blocks. A build block runs provisioner and post-processors on a 7 | # source. Read the documentation for source blocks here: 8 | # https://www.packer.io/docs/from-1.5/blocks/source 9 | 10 | source "proxmox-clone" "mhc" { 11 | proxmox_url = var.proxmox_url 12 | username = var.proxmox_api_user 13 | password = var.proxmox_api_password 14 | node = var.proxmox_node_name 15 | clone_vm = var.clone_vm_name 16 | insecure_skip_tls_verify = true 17 | pool = var.pool_name 18 | vm_name = var.vm_name 19 | vm_id = var.vm_id 20 | memory = var.memory 21 | cores = var.cores 22 | sockets = var.sockets 23 | cpu_type = var.cpu_type 24 | os = var.os_type 25 | vga { 26 | type = var.vga_type 27 | } 28 | network_adapters { 29 | bridge = "vmbr0" 30 | model = "virtio" 31 | } 32 | disks { 33 | storage_pool = var.storage_pool 34 | storage_pool_type = var.storage_pool_type 35 | type = "scsi" 36 | disk_size = var.disk_size 37 | cache_mode = "none" 38 | format = "raw" 39 | io_thread = true // Requires scsi_controller = "virtio-scsi-single" 40 | } 41 | template_name = var.template_name 42 | template_description = var.template_description 43 | onboot = false 44 | qemu_agent = true 45 | disable_kvm = false 46 | scsi_controller = "virtio-scsi-single" 47 | full_clone = true 48 | 49 | ssh_timeout = "90m" 50 | ssh_username = var.ssh_username 51 | ssh_private_key_file = var.ssh_private_key_file 52 | #ssh_password = var.ssh_password 53 | } 54 | -------------------------------------------------------------------------------- /packer/packer_proxmox-clone/variables._auto.pkrvars.hcl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarisGece/mHC/c6a2ad679deb6baf097877b6b596b9876aad5f66/packer/packer_proxmox-clone/variables._auto.pkrvars.hcl -------------------------------------------------------------------------------- /packer/packer_proxmox-clone/variables.pkr.hcl: -------------------------------------------------------------------------------- 1 | variable "proxmox_url" { 2 | type = string 3 | default = "https://192.168.50.10:8006/api2/json" 4 | description = "The hostname of Proxmox-VE node that will be accessed via the Web API" 5 | sensitive = false 6 | } 7 | 8 | variable "proxmox_api_user" { 9 | type = string 10 | default = "root@pam" 11 | description = "Proxmox-VE API User that will perform the commands on the PVE host" 12 | sensitive = true 13 | # When a variable is sensitive all string-values from that variable will be 14 | # obfuscated from Packer's output. 15 | } 16 | 17 | variable "proxmox_api_password" { 18 | type = string 19 | default = "packer" // set via Enviroment Variable 20 | description = "Password of the Proxmox-VE API User that will perform the commands on the PVE host" 21 | sensitive = true 22 | # When a variable is sensitive all string-values from that variable will be 23 | # obfuscated from Packer's output. 24 | } 25 | 26 | variable "proxmox_node_name" { 27 | type = string 28 | default = "one" 29 | description = "The name of the Proxmox-VE Node" 30 | sensitive = false 31 | } 32 | 33 | variable "clone_vm_name" { 34 | type = string 35 | default = "ubuntu2004-cloud" 36 | description = "The name of the VM packer should clone and build from" 37 | sensitive = false 38 | } 39 | 40 | variable "pool_name" { 41 | type = string 42 | default = "" 43 | description = "Name of resource pool to create virtual machine in" 44 | sensitive = false 45 | } 46 | 47 | variable "vm_name" { 48 | type = string 49 | default = "ubuntu-base-20-04-1-{{ isotime \"2006-01-02-T15-04-05\" }}" 50 | description = "Name of the Proxmox-VE Virtual Machine during creation" 51 | sensitive = false 52 | } 53 | 54 | variable "vm_id" { 55 | type = number 56 | description = "The (unique) ID of the Virtual Machine that will be created to configure the template" 57 | sensitive = false 58 | } 59 | 60 | variable "memory" { 61 | type = number 62 | default = 4096 63 | description = "Available memory on the template" 64 | sensitive = false 65 | } 66 | 67 | variable "cores" { 68 | type = number 69 | default = 2 70 | description = " The number of CPU cores per socket to give the template" 71 | sensitive = false 72 | } 73 | 74 | variable "sockets" { 75 | type = number 76 | default = 1 77 | description = "The number of CPU sockets" 78 | sensitive = false 79 | } 80 | 81 | variable "cpu_type" { 82 | type = string 83 | default = "host" 84 | description = "The CPU type to emulate. Defaults to kvm64" 85 | sensitive = false 86 | } 87 | 88 | variable "os_type" { 89 | type = string 90 | default = "l26" 91 | description = "The operating system. Defaults to other" 92 | sensitive = false 93 | } 94 | 95 | variable "vga_type" { 96 | type = string 97 | default = "serial0" 98 | description = "Can be cirrus, none, qxl,qxl2, qxl3, qxl4, serial0, serial1, serial2, serial3, std, virtio, vmware. Defaults to std." 99 | sensitive = false 100 | } 101 | 102 | variable "storage_pool" { 103 | type = string 104 | default = "local-lvm" 105 | description = "The data store the Virtual Machine OS disk will be created on" 106 | sensitive = false 107 | } 108 | 109 | variable "storage_pool_type" { 110 | type = string 111 | default = "lvm-thin" 112 | description = "The type of the OS disk data store" 113 | sensitive = false 114 | } 115 | 116 | variable "disk_size" { 117 | type = string 118 | default = "20G" 119 | description = "Operating System disk size of the template" 120 | sensitive = false 121 | } 122 | 123 | variable "template_name" { 124 | type = string 125 | default = "template-ubuntu-base-20-04-1-{{ isotime \"2006-01-02-T15-04-05\" }}" 126 | description = "Name of the Proxmox-VE Template to be created" 127 | sensitive = false 128 | } 129 | 130 | variable "template_description" { 131 | type = string 132 | default = "Ubuntu 20.04, generated by Packer on {{ isotime \"2006-01-02T15:04:05Z\" }}" 133 | description = "Description applied to the Proxmox-VE Template to be created" 134 | sensitive = false 135 | } 136 | 137 | variable "ssh_username" { 138 | type = string 139 | default = "ubuntu" 140 | description = "Default username, if modified from packer update the default preseed.cfg file d-i preseed/late_command string command and update it to your new sudoer username" 141 | sensitive = true 142 | # When a variable is sensitive all string-values from that variable will be 143 | # obfuscated from Packer's output. 144 | } 145 | 146 | variable "ssh_fullname" { 147 | type = string 148 | default = "ubuntu" 149 | description = "Default User Full Name" 150 | sensitive = true 151 | # When a variable is sensitive all string-values from that variable will be 152 | # obfuscated from Packer's output. 153 | } 154 | 155 | variable "ssh_private_key_file" { 156 | type = string 157 | default = "~/.ssh/client-id_rsa" 158 | description = "Default User Password" 159 | sensitive = true 160 | # When a variable is sensitive all string-values from that variable will be 161 | # obfuscated from Packer's output. 162 | } 163 | 164 | variable "ssh_password" { 165 | type = string 166 | default = "packer" 167 | description = "Default User Password" 168 | sensitive = true 169 | # When a variable is sensitive all string-values from that variable will be 170 | # obfuscated from Packer's output. 171 | } 172 | -------------------------------------------------------------------------------- /packer/packer_proxmox-clone/variables.pkrvars.hcl: -------------------------------------------------------------------------------- 1 | proxmox_url = "https://192.168.50.10:8006/api2/json" 2 | proxmox_api_user = "root@pam" 3 | proxmox_api_password = "packer" // set via Enviroment Variable 4 | proxmox_node_name = "one" 5 | template_name = "template-ubuntu-base-20-04-1-{{ isotime \"2006-01-02-T15-04-05\" }}" 6 | template_description = "Ubuntu 20.04, generated by Packer on {{ isotime \"2006-01-02T15:04:05Z\" }}" 7 | 8 | ssh_fullname = "packer" // set via Enviroment Variable 9 | ssh_password = "packer" // set via Enviroment Variable 10 | ssh_username = "packer" // set via Enviroment Variable 11 | 12 | vmid = 4000 13 | -------------------------------------------------------------------------------- /proxmox-ve/create-proxmox-users.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o errexit 3 | 4 | PACKER_USER=${PACKER_PVE_USER:-packer} 5 | PACKER_PASSWORD=$PACKER_PVE_PASSWORD 6 | 7 | TERRAFORM_USER=${TERRAFORM_PVE_USER:-terraform} 8 | TERRAFORM_PASSWORD=$TERRAFORM_PVE_PASSWORD 9 | 10 | ANSIBLE_USER=${ANSIBLE_PVE_USER:-ansible} 11 | ANSIBLE_PASSWORD=$ANSIBLE_PVE_PASSWORD 12 | 13 | if [[ -z $PACKER_PVE_PASSWORD ]]; then 14 | printf "\n** \033[1;31mCould not find Packer PVE Password as Environment Variable\033[0m **\n" 15 | read -s -p "Please set PACKER_PVE_PASSWORD password (at least 12 or 14 character): " PACKER_PVE_PASSWORD 16 | export PACKER_PVE_PASSWORD=$PACKER_PVE_PASSWORD 17 | printf "\n** \033[1;33mPACKER_PVE_PASSWORD Set\033[0m **\n" 18 | 19 | printf "\n** \033[1;33m$PACKER_USER will be created\033[0m **\n" 20 | pveum useradd $PACKER_USER@pve --password $PACKER_PVE_PASSWORD -comment "Packer Admin" 21 | pveum aclmod / -user $PACKER_USER@pve -role Administrator 22 | printf "\n** \033[1;33m$PACKER_USER created with Administrator Role\033[0m **\n" 23 | else 24 | printf "\n** \033[1;33m$PACKER_USER will be created\033[0m **\n" 25 | pveum useradd $PACKER_USER@pve --password $PACKER_PVE_PASSWORD -comment "Packer Admin" 26 | pveum aclmod / -user $PACKER_USER@pve -role Administrator 27 | printf "\n** \033[1;33m$PACKER_USER created with Administrator Role\033[0m **\n" 28 | fi 29 | 30 | if [[ -z $TERRAFORM_PVE_PASSWORD ]]; then 31 | printf "\n** \033[1;31mCould not find Terraform PVE Password as Environment Variable\033[0m **\n" 32 | read -s -p "Please set TERRAFORM_PVE_PASSWORD password (at least 12 or 14 character): " TERRAFORM_PVE_PASSWORD 33 | export TERRAFORM_PVE_PASSWORD=$TERRAFORM_PVE_PASSWORD 34 | printf "\n** \033[1;33mTERRAFORM_PVE_PASSWORD Set\033[0m **\n" 35 | 36 | printf "\n** \033[1;33m$TERRAFORM_USER will be created\033[0m **\n" 37 | pveum useradd $TERRAFORM_USER@pve --password $TERRAFORM_PVE_PASSWORD -comment "Terraform Admin" 38 | pveum aclmod / -user $TERRAFORM_USER@pve -role Administrator 39 | printf "\n** \033[1;33m$TERRAFORM_USER created with Administrator Role\033[0m **\n" 40 | else 41 | printf "\n** \033[1;33m$TERRAFORM_USER will be created\033[0m **\n" 42 | pveum useradd $TERRAFORM_USER@pve --password $TERRAFORM_PVE_PASSWORD -comment "Terraform Admin" 43 | pveum aclmod / -user $TERRAFORM_USER@pve -role Administrator 44 | printf "\n** \033[1;33m$TERRAFORM_USER created with Administrator Role\033[0m **\n" 45 | fi 46 | 47 | if [[ -z $ANSIBLE_PVE_PASSWORD ]]; then 48 | printf "\n** \033[1;31mCould not find Ansible PVE Password as Environment Variable\033[0m **\n" 49 | read -s -p "Please set ANSIBLE_PVE_PASSWORD password (at least 12 or 14 character): " ANSIBLE_PVE_PASSWORD 50 | export ANSIBLE_PVE_PASSWORD=$ANSIBLE_PVE_PASSWORD 51 | printf "\n** \033[1;33mANSIBLE_PVE_PASSWORD Set\033[0m **\n" 52 | 53 | printf "\n** \033[1;33m$ANSIBLE_USER will be created\033[0m **\n" 54 | pveum useradd $ANSIBLE_USER@pve --password $ANSIBLE_PVE_PASSWORD -comment "Ansible Admin" 55 | pveum aclmod / -user $ANSIBLE_USER@pve -role Administrator 56 | printf "\n** \033[1;33m$ANSIBLE_USER created with Administrator Role\033[0m **\n" 57 | else 58 | printf "\n** \033[1;33m$ANSIBLE_USER will be created\033[0m **\n" 59 | pveum useradd $ANSIBLE_USER@pve --password $ANSIBLE_PVE_PASSWORD -comment "Ansible Admin" 60 | pveum aclmod / -user $ANSIBLE_USER@pve -role Administrator 61 | printf "\n** \033[1;33m$ANSIBLE_USER created with Administrator Role\033[0m **\n" 62 | fi 63 | -------------------------------------------------------------------------------- /proxmox-ve/create-template-via-cloudinit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o errexit 3 | 4 | printf "\n*** Packages will be updated ***\n\n" 5 | apt-get update 6 | apt-get -y upgrade 7 | apt-get -y dist-upgrade 8 | 9 | printf "\n*** Packages Updated. Proxmox VM Template creation will start after 5 seconds ***\n\n" 10 | sleep 5 11 | 12 | clear 13 | printf "\n*** This script will download a cloud image and create a Proxmox VM template from it. ***\n\n" 14 | 15 | printf "\n*** Do you wish to execute script on Proxmox-VE? ***\n\n" 16 | select yn in "Yes" "No"; do 17 | case $yn in 18 | Yes ) break;; 19 | No ) exit;; 20 | esac 21 | done 22 | 23 | ### NOTES: 24 | ### - Links to Cloud Images: 25 | ### Directory : https://docs.openstack.org/image-guide/obtain-images.html 26 | ### Debian : http://cdimage.debian.org/cdimage/cloud/OpenStack/ 27 | ### Ubuntu : http://cloud-images.ubuntu.com/ 28 | ### RancherOS : https://github.com/rancher/os/releases (Also includes Proxmox iso version) 29 | ### Flatcar (CoreOS fork) : https://stable.release.flatcar-linux.net/amd64-usr/?sort=time&order=desc - https://www.flatcar-linux.org/ 30 | ### CentOS : https://cloud.centos.org/centos/ 31 | ### Arch (also Gentoo) : https://linuximages.de/openstack/arch/ 32 | ### Fedora : https://alt.fedoraproject.org/cloud/ 33 | ### Gentoo : http://gentoo.osuosl.org/experimental/amd64/openstack 34 | ### SUSE 15 SP1 JeOS : https://download.suse.com/Download?buildid=OE-3enq3uys~ 35 | ### CirrOS : http://download.cirros-cloud.net/ 36 | 37 | ## TODO 38 | ### - verify authenticity of downloaded images using hash or GPG 39 | 40 | printf "\nAvailable templates to generate:\n 2) Debian 9\n 3) Debian 10\n 4) Ubuntu 18.04\n 5) Ubuntu 20.04\n 6) RancherOS 1.5.5\n 7) CoreOS/Flatcar\n 8) Centos 7\n 9) Arch\n\n" 41 | read -p "Enter number of distro to use: " OSNR 42 | read -p "Enter Proxmox VE Node Name: " NNAME 43 | 44 | # defaults which are used for most templates 45 | KVM=1 46 | NUMA=1 47 | HOTPLUG=disk,network,usb,cpu,memory 48 | CPUTYPE=host 49 | CORES=2 50 | SOCKETS=1 51 | vCPUs=2 52 | MEMORY=2048 53 | BRIDGE=vmbr0 54 | FIREWALL=0 55 | AUTOSTART=1 56 | ONBOOT=1 57 | OSTYPE=l26 58 | DISKCACHE=none 59 | CITYPE=nocloud 60 | RESIZE=8G #+30G 61 | NODENAME=$NNAME 62 | SNIPPETSPATH=/snippets/snippets 63 | USERCONFIG_DEFAULT=sample-cloud-init-config.yml 64 | SSHKEY_DEFAULT_CLIENT_NAME=client-id_rsa # DO NOT USE ~/.ssh/id_rsa.pub 65 | NOTE="" 66 | 67 | printf "\n*** SSH Keys will be generated to connect Proxmox/Client to VM via SSH ***\n\n" 68 | read -p "Enter a SSH KEY Name for Clients [Click enter to use default ssh client name: $SSHKEY_DEFAULT_CLIENT_NAME]: " SSHKEY_CLIENT_NAME 69 | SSHKEY_CLIENT_NAME=${SSHKEY_CLIENT_NAME:-$SSHKEY_DEFAULT_CLIENT_NAME} 70 | SSHKEY_CLIENT=~/.ssh/$SSHKEY_CLIENT_NAME.pub 71 | if [[ ! -f $SSHKEY_CLIENT ]] ; then 72 | ssh-keygen -f ~/.ssh/$SSHKEY_CLIENT_NAME -t rsa -b 4096 -C "Client@VM" 73 | #ssh-keygen -f ~/.ssh/$SSHKEY_CLIENT_NAME -t rsa -b 4096 -P client -C "Client@VM" 74 | printf "\n** $SSHKEY_CLIENT generated **\n\n" 75 | else 76 | printf "\n** $SSHKEY_CLIENT IS EXISTS **\n\n" 77 | fi 78 | 79 | case $OSNR in 80 | 81 | 2) 82 | OSNAME=debian9 83 | VMID_DEFAULT=51000 84 | read -p "Enter a VM ID for $OSNAME [$VMID_DEFAULT]: " VMID 85 | VMID=${VMID:-$VMID_DEFAULT} 86 | VMIMAGE_DEFAULT=debian-9-openstack-amd64.qcow2 87 | read -p "Enter a VM IMAGE NAME for $OSNAME [Click enter to use default image: $VMIMAGE_DEFAULT]: " VMIMAGE 88 | VMIMAGE=${VMIMAGE:-$VMIMAGE_DEFAULT} 89 | NOTE="\n## Default user is 'debian'\n## NOTE: Setting a password via cloud-config does not work.\n" 90 | printf "$NOTE\n" 91 | wget -P /tmp -N https://cdimage.debian.org/cdimage/openstack/current-9/$VMIMAGE 92 | ;; 93 | 94 | 3) 95 | OSNAME=debian10 96 | VMID_DEFAULT=51100 97 | read -p "Enter a VM ID for $OSNAME [$VMID_DEFAULT]: " VMID 98 | VMID=${VMID:-$VMID_DEFAULT} 99 | VMIMAGE_DEFAULT=debian-10-openstack-amd64.qcow2 100 | read -p "Enter a VM IMAGE NAME for $OSNAME [Click enter to use default image: $VMIMAGE_DEFAULT]: " VMIMAGE 101 | VMIMAGE=${VMIMAGE:-$VMIMAGE_DEFAULT} 102 | NOTE="\n## Default user is 'debian'\n" 103 | printf "$NOTE\n" 104 | wget -P /tmp -N https://cdimage.debian.org/cdimage/openstack/current-10/$VMIMAGE 105 | ;; 106 | 107 | 4) 108 | OSNAME=ubuntu1804 109 | VMID_DEFAULT=52000 110 | read -p "Enter a VM ID for $OSNAME [$VMID_DEFAULT]: " VMID 111 | VMID=${VMID:-$VMID_DEFAULT} 112 | VMIMAGE_DEFAULT=bionic-server-cloudimg-amd64.img 113 | read -p "Enter a VM IMAGE NAME for $OSNAME [Click enter to use default image: $VMIMAGE_DEFAULT]: " VMIMAGE 114 | VMIMAGE=${VMIMAGE:-$VMIMAGE_DEFAULT} 115 | NOTE="\n## Default user is 'ubuntu'\n" 116 | printf "$NOTE\n" 117 | wget -P /tmp -N https://cloud-images.ubuntu.com/bionic/current/$VMIMAGE 118 | ;; 119 | 120 | 5) 121 | OSNAME=ubuntu2004 122 | VMID_DEFAULT=52100 123 | read -p "Enter a VM ID for $OSNAME [$VMID_DEFAULT]: " VMID 124 | VMID=${VMID:-$VMID_DEFAULT} 125 | VMIMAGE_DEFAULT=focal-server-cloudimg-amd64.img 126 | read -p "Enter a VM IMAGE NAME for $OSNAME [Click enter to use default image: $VMIMAGE_DEFAULT]: " VMIMAGE 127 | VMIMAGE=${VMIMAGE:-$VMIMAGE_DEFAULT} 128 | NOTE="\n## Default user is 'ubuntu'\n" 129 | printf "$NOTE\n" 130 | wget -P /tmp -N https://cloud-images.ubuntu.com/focal/current/$VMIMAGE 131 | ;; 132 | 133 | 6) 134 | OSNAME=rancheros 135 | VMID_DEFAULT=53000 136 | read -p "Enter a VM ID for $OSNAME [$VMID_DEFAULT]: " VMID 137 | VMID=${VMID:-$VMID_DEFAULT} 138 | VMIMAGE_DEFAULT=rancheros-openstack.img 139 | VMIMAGE_VERSION_DEFAULT=v1.5.6 140 | read -p "Enter a VM IMAGE VERSION for $OSNAME [Click enter to use default version: $VMIMAGE_VERSION_DEFAULT]: " VMIMAGE_VERSION 141 | read -p "Enter a VM IMAGE NAME for $OSNAME [Click enter to use default image: $VMIMAGE_DEFAULT]: " VMIMAGE 142 | VMIMAGE_VERSION=${VMIMAGE_VERSION:-$VMIMAGE_VERSION_DEFAULT} 143 | VMIMAGE=${VMIMAGE:-$VMIMAGE_DEFAULT} 144 | CITYPE=configdrive2 145 | NOTE="\n## Default user is 'rancher'\n## NOTE: Setting a password via cloud-config does not work.\n# RancherOS does autologin on console.\n" 146 | printf "$NOTE\n" 147 | wget -P /tmp -N https://github.com/rancher/os/releases/download/$VMIMAGE_VERSION/$VMIMAGE 148 | ;; 149 | 150 | 7) 151 | OSNAME=flatcar 152 | VMID_DEFAULT=54000 153 | read -p "Enter a VM ID for $OSNAME [$VMID_DEFAULT]: " VMID 154 | VMID=${VMID:-$VMID_DEFAULT} 155 | RESIZE=+24G 156 | VMIMAGE_DEFAULT=flatcar_production_qemu_image.img.bz2 157 | VMIMAGE_VERSION_DEFAULT=2605.7.0 158 | read -p "Enter a VM IMAGE VERSION for $OSNAME [Click enter to use default version: $VMIMAGE_VERSION_DEFAULT]: " VMIMAGE_VERSION 159 | read -p "Enter a VM IMAGE NAME for $OSNAME [Click enter to use default image: $VMIMAGE_DEFAULT]: " VMIMAGE 160 | VMIMAGE_VERSION=${VMIMAGE_VERSION:-$VMIMAGE_VERSION_DEFAULT} 161 | VMIMAGE=${VMIMAGE:-$VMIMAGE_DEFAULT} 162 | CITYPE=configdrive2 163 | NOTE="\n## Default user is 'coreos'\n## NOTE: Setting a password via cloud-config does not work.\n" 164 | printf "$NOTE\n" 165 | wget -P /tmp -N https://stable.release.flatcar-linux.net/amd64-usr/$VMIMAGE_VERSION/$VMIMAGE 166 | ;; 167 | 168 | 8) 169 | OSNAME=centos7 170 | VMID_DEFAULT=56000 171 | read -p "Enter a VM ID for $OSNAME [$VMID_DEFAULT]: " VMID 172 | VMID=${VMID:-$VMID_DEFAULT} 173 | RESIZE=+24G 174 | VMIMAGE_DEFAULT=CentOS-7-x86_64-GenericCloud.qcow2 175 | read -p "Enter a VM IMAGE NAME for $OSNAME [Click enter to use default image: $VMIMAGE_DEFAULT]: " VMIMAGE 176 | VMIMAGE=${VMIMAGE:-$VMIMAGE_DEFAULT} 177 | NOTE="\n## Default user is 'centos'\n## NOTE: CentOS ignores hostname config.\n# use 'hostnamectl set-hostname centos7-cloud' inside VM\n" 178 | printf "$NOTE\n" 179 | wget -P /tmp -N http://cloud.centos.org/centos/7/images/$VMIMAGE 180 | ;; 181 | 182 | 9) 183 | OSNAME=arch 184 | VMID_DEFAULT=57000 185 | read -p "Enter a VM ID for $OSNAME [$VMID_DEFAULT]: " VMID 186 | VMID=${VMID:-$VMID_DEFAULT} 187 | RESIZE=+29G 188 | VMIMAGE=arch-openstack-LATEST-image-bootstrap.qcow2 189 | NOTE="\n## Default user is 'arch'\n## NOTE: Setting a password via cloud-config does not work.\n# Resizing does not happen automatically inside the VM\n" 190 | printf "$NOTE\n" 191 | wget -P /tmp -N https://linuximages.de/openstack/arch/$VMIMAGE 192 | ;; 193 | 194 | *) 195 | printf "\n** Unknown OS number. Please use one of the above! **\n" 196 | exit 0 197 | ;; 198 | esac 199 | 200 | [[ $VMIMAGE == *".bz2" ]] \ 201 | && printf "\n** Uncompressing image (waiting to complete...) **\n" \ 202 | && bzip2 -d --force /tmp/$VMIMAGE \ 203 | && VMIMAGE=$(echo "${VMIMAGE%.*}") # remove .bz2 file extension from file name 204 | 205 | # TODO: could prompt for the VM name 206 | echo -e \ 207 | " \033[2;32m** Creating a VM with **\033[0m\n" \ 208 | " \033[1;2;34mVMID :\033[0m \033[1;33m$VMID\033[0m\n" \ 209 | " \033[1;2;34mVM Name :\033[0m \033[1;33m$OSNAME-cloud-template\033[0m\n" \ 210 | " \033[1;2;34mKVM Enabled :\033[0m \033[1;33m$KVM\033[0m\n" \ 211 | " \033[1;2;34mNUMA Enabled :\033[0m \033[1;33m$NUMA\033[0m\n" \ 212 | " \033[1;2;34mHOTPLUG :\033[0m \033[1;33m$HOTPLUG\033[0m\n" \ 213 | " \033[1;2;34mCPU Type :\033[0m \033[1;33m$CPUTYPE\033[0m\n" \ 214 | " \033[1;2;34mCPU Cores :\033[0m \033[1;33m$CORES\033[0m\n" \ 215 | " \033[1;2;34mCPU Sockets :\033[0m \033[1;33m$SOCKETS\033[0m\n" \ 216 | " \033[1;2;34mHotplugged vCPUs :\033[0m \033[1;33m$vCPUs\033[0m\n" \ 217 | " \033[1;2;34mMEMORY :\033[0m \033[1;33m$MEMORY\033[0m\n" \ 218 | " \033[1;2;34mNetwork :\033[0m \033[1;33mBRIDGE=$BRIDGE & FIREWALL=$FIREWALL\033[0m\n" \ 219 | " \033[1;2;34mQemu Guest Agent :\033[0m \033[1;33menabled=1 & type=virtio\033[0m\n" \ 220 | " \033[1;2;34mAuto Start :\033[0m \033[1;33mRestart After Crash=$AUTOSTART\033[0m\n" \ 221 | " \033[1;2;34mOn Boot :\033[0m \033[1;33mVM will be started during system bootup=$ONBOOT\033[0m\n" \ 222 | " \033[1;2;34mGuest OS :\033[0m \033[1;33m$OSTYPE\033[0m\n" 223 | 224 | qm create $VMID --name $OSNAME-cloud-template --kvm $KVM --numa $NUMA --hotplug $HOTPLUG --cpu $CPUTYPE --cores $CORES --sockets $SOCKETS --vcpus $vCPUs --memory $MEMORY --net0 virtio,bridge=$BRIDGE,firewall=$FIREWALL --agent enabled=1,fstrim_cloned_disks=1,type=virtio --autostart $AUTOSTART --onboot $ONBOOT --ostype $OSTYPE 225 | 226 | printf "\n** \033[1;33mImporting the disk in raw format (as 'Unused Disk 0')\033[0m **\n" 227 | qm importdisk $VMID /tmp/$VMIMAGE local-lvm --format raw # --format qcow2 228 | 229 | printf "\n** \033[1;33mAttaching the disk to the VM using VirtIO SCSI Single\033[0m **\n" 230 | qm set $VMID --scsihw virtio-scsi-single --scsi0 local-lvm:vm-$VMID-disk-0,cache=$DISKCACHE,iothread=1 231 | 232 | printf "\n** \033[1;32mCreating a cloudinit drive managed by Proxmox\033[0m **\n" 233 | qm set $VMID --ide2 local-lvm:cloudinit 234 | 235 | printf "\n** \033[1;32mSpecifying the cloud-init configuration format\033[0m **\n" 236 | qm set $VMID --citype $CITYPE 237 | 238 | printf "\n** \033[1;33mSetting boot and display settings with serial console\033[0m **\n" 239 | qm set $VMID --boot c --bootdisk scsi0 --serial0 socket --vga serial0 240 | 241 | printf "\n** \033[1;33mUsing a dhcp server on $BRIDGE (or change to static IP)\033[0m **\n" 242 | qm set $VMID --ipconfig0 ip=dhcp 243 | #This would work in a bridged setup, but a routed setup requires a route to be added in the guest 244 | #qm set $VMID --ipconfig0 ip=10.10.10.222/24,gw=10.10.10.1 245 | 246 | ## TODO: Also ask for a network configuration. Or create a config with routing for a static IP 247 | printf "\n*** The script can add a cloud-init configuration with users and SSH keys from a file in the current directory. ***\n" 248 | read -p "Supply the name of the cloud-init-config.yml (this will be skipped, if file not found) [$USERCONFIG_DEFAULT]: " USERCONFIG 249 | USERCONFIG=${USERCONFIG:-$USERCONFIG_DEFAULT} 250 | if [[ -f $PWD/$USERCONFIG ]] 251 | then 252 | # The cloud-init user config file overrides the user settings done elsewhere 253 | printf "\n** \033[1;32mAdding user configuration\033[0m **\n" 254 | cp -v $PWD/$USERCONFIG $SNIPPETSPATH/$VMID-$OSNAME-$USERCONFIG 255 | qm set $VMID --cicustom "user=snippets:snippets/$VMID-$OSNAME-$USERCONFIG" 256 | printf "# cloud-config: $VMID-$OSNAME-$USERCONFIG\n" >> /etc/pve/nodes/$NODENAME/qemu-server/$VMID.conf 257 | else 258 | # The SSH key should be supplied either in the cloud-init config file or here 259 | printf "\n** \033[1;32mSkipping config file, as none was found\033[0m\n\n** Adding SSH key **\n" 260 | qm set $VMID --sshkey $SSHKEY_CLIENT 261 | printf "\n" 262 | read -s -p "Supply an optional password for the default user (press Enter for none): " PASSWORD 263 | [[ ! -z "$PASSWORD" ]] \ 264 | && printf "\n** Adding the password to the config **\n" \ 265 | && qm set $VMID --cipassword $PASSWORD \ 266 | && printf "# A password has been set for the default user\n" >> /etc/pve/nodes/$NODENAME/qemu-server/$VMID.conf 267 | printf "# cloud-config used: via Proxmox\n" >> /etc/pve/nodes/$NODENAME/qemu-server/$VMID.conf 268 | fi 269 | 270 | # The NOTE is added to the Summary section of the VM (TODO there seems to be no 'qm' command for this) 271 | printf "#$NOTE\n" >> /etc/pve/nodes/$NODENAME/qemu-server/$VMID.conf 272 | 273 | printf "\n** \033[1;33mIncreasing the disk size\033[0m **\n" 274 | qm resize $VMID scsi0 $RESIZE 275 | 276 | printf "\n*** The following cloud-init configuration will be used ***\n" 277 | if [[ -f $PWD/$USERCONFIG ]] 278 | then 279 | cat $PWD/$USERCONFIG 280 | else 281 | printf "\n------------- User ------------------\n" 282 | qm cloudinit dump $VMID user 283 | printf "\n------------- Network ---------------\n" 284 | qm cloudinit dump $VMID network 285 | fi 286 | 287 | printf "\n\033[1;33m------------- Convert the VM into a Template ---------------\033[0m\n" 288 | qm template $VMID 289 | 290 | printf "\n------------- Copy downloaded Image file into Templates Folder ---------------\n" 291 | if [[ ! -f /var/lib/vz/template/iso/$VMIMAGE ]] ; then 292 | cp /tmp/$VMIMAGE /var/lib/vz/template/iso/$VMIMAGE 293 | printf "$VMIMAGE Copied into /var/lib/vz/template/iso/ \n\n" 294 | else 295 | printf "$VMIMAGE is Exists\n\n" 296 | fi 297 | 298 | while true; do 299 | read -p "Are you running Proxmox-VE in Cluster Mode and want to distribute the downloaded Image & SSHKEY files to all nodes (yes or no): " yn 300 | case $yn in 301 | [Yy]* ) 302 | printf "\nPlease enter the IPs of the Nodes wanted to distribute the downloaded Image file, separated by 'SPACE' (192.168.50.50) : " 303 | read -a CLUSTER_NODE_IPS 304 | for i in ${!CLUSTER_NODE_IPS[@]} 305 | do 306 | scp ~/.ssh/$SSHKEY_CLIENT_NAME.pub root@${CLUSTER_NODE_IPS[i]}:~/.ssh/ 307 | scp ~/.ssh/$SSHKEY_CLIENT_NAME root@${CLUSTER_NODE_IPS[i]}:~/.ssh/ 308 | printf "\n** $SSHKEY_CLIENT_NAME copied to ${CLUSTER_NODE_IPS[i]}:~/.ssh/ **\n\n" 309 | scp /tmp/$VMIMAGE root@${CLUSTER_NODE_IPS[i]}:/tmp 310 | ssh root@${CLUSTER_NODE_IPS[i]} "cp /tmp/$VMIMAGE /var/lib/vz/template/iso/" 311 | printf "\n** $VMIMAGE copied to ${CLUSTER_NODE_IPS[i]}:/var/lib/vz/template/iso/ & /tmp Folders**\n\n" 312 | done 313 | break;; 314 | [Nn]* ) break;; 315 | * ) echo "Please answer yes or no.";; 316 | esac 317 | done 318 | 319 | printf "\n** Removing previously downloaded image file **\n\n" 320 | rm -v /tmp/$VMIMAGE 321 | 322 | printf "$NOTE\n\n" 323 | -------------------------------------------------------------------------------- /proxmox-ve/sample-cloud-init-config.yml: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | package_upgrade: true 3 | packages: 4 | - nmap 5 | - bmon #A Powerful Network Bandwidth Monitoring and Debugging Tool for Linux 6 | - atop 7 | - iotop 8 | - iperf3 9 | - curl 10 | - wget 11 | - git 12 | - fail2ban 13 | - qemu-guest-agent 14 | users: 15 | - name: ubuntu 16 | groups: sudo 17 | shell: /bin/bash 18 | sudo: ['ALL=(ALL) NOPASSWD:ALL'] 19 | ssh_authorized_keys: 20 | - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDMsWy4xtV23AVHwNSZKokocJjBJQkZ6GtFKNfh5BWbfG48b0BwNS+i5fKReXOdTS1kyI+NWCZxT+9eLbF+w7dsqj1ArsZP96so22slPCv+hRmj1a84cDiglXXMzC2DuYx9Qz2q4tUWoM/GQGWrqqF/abS9QG1/a3SGg+KgCIR2gP2Iakvb/zPKKUV3CfSEm1tibu34T1+aZVjypcoFfDDDNz0eU5FBD/1puWVImZ28k8gOnFSz5Hw6Rvr/XpQW5uLj6T8bNYmMxf8hn40qzH7dQgUbP3KJVbEGTmKlREKEIFJfQyryRdYjBgA08mQo9XFNu4zcI9ruwdVYB6C9dRCFYBBwii3ddMhuhbBk5vbOdVTi1ODIT0ncFsRmtKoNYNhwMl6NZXOePxXbbj4hJuqAOeLF/DevXXFuVfvlTsfa274APyZFIBIT2WExJRKmREdItlAxH8WUk0oX3jaBT6HPGJCzn6Qgiq2LtZq79PKtn5aJjwkYFuumpbfKY2k4EE/8DakS5W3ug3GY/5AnBY+hV0QSfFP2z6xnXEOeP6p1G5zcsWsxcQb5jw+KGupueybaMIBRIPuB6kmoba2Ebk7V1pUuUFxLleB4AuOMxnVNWFE6NXIFF+h11FzIvygAsqDW7A75BXKmCvMhYOyevSHKq9KwnN6RwuE5kD5APN+Anw== Client@VM 21 | runcmd: 22 | - sudo systemctl start qemu-guest-agent 23 | - sudo systemctl enable qemu-guest-agent 24 | - sudo sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin no/' /etc/ssh/sshd_config 25 | - sudo sed -i 's|[#]*PasswordAuthentication yes|PasswordAuthentication no|g' /etc/ssh/sshd_config 26 | - echo -e 'modprobe acpiphp' | sudo tee -a /etc/modules >/dev/nul 27 | - echo -e 'modprobe pci_hotplug' | sudo tee -a /etc/modules >/dev/nul 28 | - sudo sed -i 's|GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"|GRUB_CMDLINE_LINUX_DEFAULT="quiet splash memhp_default_state=online"|g' /etc/default/grub 29 | - sudo update-grub 30 | power_state: 31 | delay: now 32 | mode: reboot 33 | message: Rebooting the OS 34 | #timeout: 30 35 | condition: true 36 | #condition: if [ -e /var/run/reboot-required ]; then exit 0; else exit 1; fi 37 | final_message: "The system is finally up, after $UPTIME seconds" 38 | # cloud-init logs: /var/log/cloud-init.log and /var/log/cloud-init-output.log -------------------------------------------------------------------------------- /terraform/main.tf: -------------------------------------------------------------------------------- 1 | resource "proxmox_vm_qemu" "rancher" { 2 | count = var.create_vm ? 1 : 0 3 | 4 | name = var.name 5 | target_node = var.target_node 6 | vmid = var.vmid 7 | desc = var.desc 8 | bios = var.bios 9 | onboot = var.onboot 10 | boot = var.boot 11 | bootdisk = var.bootdisk 12 | agent = var.agent 13 | clone = var.clone 14 | full_clone = var.full_clone 15 | qemu_os = var.qemu_os 16 | memory = var.memory 17 | balloon = var.balloon 18 | cores = var.cores 19 | sockets = var.sockets 20 | vcpus = var.vcpus 21 | cpu = var.cpu 22 | numa = var.numa 23 | kvm = var.kvm 24 | hotplug = var.hotplug 25 | scsihw = var.scsihw 26 | 27 | dynamic "vga" { 28 | for_each = var.vga == null ? [] : list(var.vga) 29 | content { 30 | type = vga.value.type 31 | memory = vga.value.memory 32 | } 33 | } 34 | 35 | dynamic "network" { 36 | for_each = var.vm_network 37 | content { 38 | model = network.value.model 39 | macaddr = network.value.macaddr 40 | bridge = network.value.bridge 41 | tag = network.value.tag 42 | firewall = network.value.firewall 43 | rate = network.value.rate 44 | queues = network.value.queues 45 | link_down = network.value.link_down 46 | } 47 | } 48 | 49 | dynamic "disk" { 50 | for_each = var.vm_disk 51 | content { 52 | type = disk.value.type 53 | storage = disk.value.storage 54 | size = disk.value.size 55 | format = disk.value.format 56 | cache = disk.value.cache 57 | backup = disk.value.backup 58 | iothread = disk.value.iothread 59 | replicate = disk.value.replicate 60 | ssd = disk.value.ssd 61 | discard = disk.value.discard 62 | mbps = disk.value.mbps 63 | mbps_rd = disk.value.mbps_rd 64 | mbps_rd_max = disk.value.mbps_rd_max 65 | mbps_wr = disk.value.mbps_wr 66 | mbps_wr_max = disk.value.mbps_wr_max 67 | file = disk.value.file 68 | media = disk.value.media 69 | volume = disk.value.volume 70 | slot = disk.value.slot 71 | } 72 | } 73 | 74 | dynamic "serial" { 75 | for_each = var.serial == null ? [] : list(var.serial) 76 | content { 77 | id = serial.value.id 78 | type = serial.value.type 79 | } 80 | } 81 | 82 | lifecycle { 83 | ignore_changes = [ 84 | network, 85 | ] 86 | } 87 | 88 | connection { 89 | user = "packer" 90 | host = self.ssh_host 91 | private_key = data.local_file.private_key.content 92 | } 93 | 94 | provisioner "remote-exec" { 95 | inline = [ 96 | "/sbin/ip a" 97 | ] 98 | } 99 | } 100 | 101 | data "local_file" "public_key" { 102 | filename = "${path.module}/id_rsa.pub" 103 | } -------------------------------------------------------------------------------- /terraform/provider.tf: -------------------------------------------------------------------------------- 1 | provider "proxmox" { 2 | pm_api_url = var.api_url 3 | pm_user = var.user 4 | pm_password = var.password 5 | #pm_otp = var.otp 6 | pm_tls_insecure = var.tls_insecure 7 | #pm_parallel = var.parallel 8 | pm_log_enable = var.log_enable 9 | pm_log_levels = var.log_levels 10 | pm_log_file = var.log_file 11 | pm_timeout = var.timeout 12 | } 13 | -------------------------------------------------------------------------------- /terraform/terraform.tfvars: -------------------------------------------------------------------------------- 1 | name = var.name 2 | target_node = var.target_node 3 | vmid = var.vmid 4 | desc = var.desc 5 | bios = var.bios 6 | onboot = var.onboot 7 | boot = var.boot 8 | bootdisk = var.bootdisk 9 | agent = var.agent 10 | clone = var.clone 11 | full_clone = var.full_clone 12 | qemu_os = var.qemu_os 13 | memory = var.memory 14 | balloon = var.balloon 15 | cores = var.cores 16 | sockets = var.sockets 17 | vcpus = var.vcpus 18 | cpu = var.cpu 19 | numa = var.numa 20 | kvm = var.kvm 21 | hotplug = var.hotplug 22 | scsihw = var.scsihw 23 | -------------------------------------------------------------------------------- /terraform/variables.tf: -------------------------------------------------------------------------------- 1 | ######################################################################################### 2 | # Arguments are supported in the Terraform Telmate Proxmox 3 | # ** Provider Block ** 4 | ######################################################################################### 5 | 6 | variable "api_url" { 7 | description = "This is the target Proxmox API endpoint. REQUIRED(or use environment variable PM_API_URL)" 8 | type = string 9 | default = "https://proxmox.example.com:8006/api2/json" 10 | } 11 | 12 | variable "user" { 13 | description = "The Proxmox User. REQUIRED(or use environment variable PM_USER)" 14 | type = string 15 | default = "terraform@pam" 16 | } 17 | 18 | variable "password" { 19 | description = "The Proxmox User Password. REQUIRED(or use environment variable PM_PASS)" 20 | type = string 21 | default = null 22 | } 23 | 24 | variable "otp" { 25 | description = "The 2FA OTP code. (or use environment variable PM_OTP)" 26 | type = string 27 | default = null 28 | } 29 | 30 | variable "tls_insecure" { 31 | description = "Disable TLS verification while connecting. Default: false" 32 | type = string 33 | default = true 34 | } 35 | 36 | variable "parallel" { 37 | description = "Allowed simultaneous Proxmox processes(e.g. creating resources). Default: 4" 38 | type = number 39 | default = null 40 | } 41 | 42 | variable "log_enable" { 43 | description = "Enable debug logging, see the section below for logging details. Default: false" 44 | type = string 45 | default = true 46 | } 47 | 48 | variable "log_levels" { 49 | description = "A map of log sources and levels" 50 | type = map(object({ 51 | _default = string 52 | _capturelog = string 53 | })) 54 | default = {} 55 | } 56 | 57 | variable "log_file" { 58 | description = "If logging is enabled, the log file the provider will write logs to. Default: terraform-plugin-proxmox.log" 59 | type = string 60 | default = "terraform-proxmox.log" 61 | } 62 | 63 | variable "timeout" { 64 | description = "Timeout value (seconds) for proxmox API calls. Default: 300" 65 | type = number 66 | default = 600 67 | } 68 | 69 | ######################################################################################### 70 | # Arguments are supported in the Terraform Telmate Proxmox 71 | # ** Resource Block ** 72 | ######################################################################################### 73 | 74 | variable "create_vm" { 75 | description = "Check for VM Creation" 76 | type = bool 77 | default = true 78 | } 79 | 80 | variable "name" { 81 | description = "Name of the VM. REQUIRED" 82 | type = string 83 | default = null 84 | } 85 | 86 | variable "target_node" { 87 | description = "Target Proxmox-VE Node to place the VM on. REQUIRED" 88 | type = string 89 | default = null 90 | } 91 | 92 | variable "vmid" { 93 | description = "The (unique) ID of the VM in Proxmox. Default: next number in the sequence" 94 | type = number 95 | default = 1000 96 | } 97 | 98 | variable "desc" { 99 | description = "Description for the VM. Only used on the configuration web interface. This is saved as comment inside the configuration file" 100 | type = string 101 | default = null 102 | } 103 | 104 | variable "bios" { 105 | description = "Select BIOS implementation(ovmf | seabios). Default: seabios" 106 | type = string 107 | default = "seabios" 108 | } 109 | 110 | variable "onboot" { 111 | description = "Specifies whether a VM will be started during system bootup. Default: true" 112 | type = bool 113 | default = true 114 | } 115 | 116 | variable "boot" { 117 | description = "Boot on floppy (a), hard disk (c), CD-ROM (d), or network (n). Default: cdn" 118 | type = string 119 | default = "cdn" 120 | } 121 | 122 | variable "bootdisk" { 123 | description = "Enable booting from specified disk(ide|sata|scsi|virtio)\\d+. Sample: scsi0 or virtio0" 124 | type = string 125 | default = "scsi0" 126 | } 127 | 128 | variable "agent" { 129 | description = "Enables QEMU Agent option for this VM. When 1, then qemu-guest-agent must be installed on the guest. Default: 0" 130 | type = number 131 | default = 1 132 | } 133 | 134 | variable "iso" { 135 | description = "ISO file uploaded on the Proxmox-VE storage. Set only ISO or CLONE. Sample: local:iso/proxmox-mailgateway_2.1.iso" 136 | type = string 137 | default = null 138 | } 139 | 140 | variable "clone" { 141 | description = "The name of the Proxmox-VE Template. It will be used to provision a new VM by Terraform" 142 | type = string 143 | default = null 144 | } 145 | 146 | variable "full_clone" { 147 | description = "Whether to run a full or linked clone from the template. Default: true" 148 | type = bool 149 | default = true 150 | } 151 | 152 | variable "hastate" { 153 | description = "HA, you need to use a shared disk for this feature (ex: rbd)" 154 | type = string 155 | default = null 156 | } 157 | 158 | variable "qemu_os" { 159 | description = "Specify guest operating system. This is used to enable special optimization/features for specific operating systems. Default: l26" 160 | type = string 161 | default = "l26" 162 | } 163 | 164 | variable "memory" { 165 | description = "Amount of RAM for the VM in MB. This is the maximum available memory when you use the balloon device. Default: 512" 166 | type = number 167 | default = 512 168 | } 169 | 170 | variable "balloon" { 171 | description = "Amount of target RAM for the VM in MB. Using 0 disables the ballon driver. Default: 0" 172 | type = number 173 | default = 1 174 | } 175 | 176 | variable "cores" { 177 | description = "The number of CPU cores per socket to give the VM. Default: 1" 178 | type = number 179 | default = 1 180 | } 181 | 182 | variable "sockets" { 183 | description = "The number of CPU sockets. Default: 1" 184 | type = number 185 | default = 1 186 | } 187 | 188 | variable "vcpus" { 189 | description = "Number of hotplugged vCPUs. Default: 0" 190 | type = number 191 | default = 1 192 | } 193 | 194 | variable "cpu" { 195 | description = "Emulated CPU type. For best performance(homogeneous cluster where all nodes have the same CPU), set this to host. Default: host" 196 | type = string 197 | default = "host" 198 | } 199 | 200 | variable "numa" { 201 | description = "Enable/disable NUMA. Default: false" 202 | type = bool 203 | default = true 204 | } 205 | 206 | variable "kvm" { 207 | description = "Enable/disable KVM hardware virtualization. Default: true" 208 | type = bool 209 | default = true 210 | } 211 | 212 | variable "hotplug" { 213 | description = "Selectively enable hotplug features. This is a comma separated list of hotplug features: network, disk, cpu, memory and usb. Default: network,disk,usb" 214 | type = string 215 | default = "disk,network,usb,cpu,memory " 216 | } 217 | 218 | variable "scsihw" { 219 | description = "SCSI controller model. (lsi | lsi53c810 | megasas | pvscsi | virtio-scsi-pci | virtio-scsi-single)" 220 | type = string 221 | default = "virtio-scsi-single" 222 | } 223 | 224 | /* 225 | ** memory : - Sets the VGA memory (in MiB). Has no effect with serial display. (4 - 512) 226 | ** type : Default: "std" - Set the VGA type (cirrus | none | qxl | qxl2 | qxl3 | qxl4 | serial0 | serial1 | serial2 | serial3 | std | virtio | vmware) 227 | */ 228 | variable "vga" { 229 | description = "Configure the VGA Hardware. Default(for type): std" 230 | type = object({ 231 | type = string 232 | memory = number 233 | }) 234 | default = null 235 | } 236 | 237 | /* 238 | ** model : REQUIRED - Network Card Model. The virtio model provides the best performance with very low CPU overhead 239 | If your guest does not support this driver, it is usually best to use e1000 240 | (e1000 | e1000-82540em | e1000-82544gc | e1000-82545em | i82551 | i82557b | i82559er | ne2k_isa | ne2k_pci | pcnet | rtl8139 | virtio | vmxnet3) 241 | ** macaddr : - A common MAC address with the I/G (Individual/Group) bit not set 242 | ** bridge : Default: "nat" - However; The Proxmox VE standard bridge is called vmbr0. Bridge to attach the network device to 243 | ** tag : Default: -1 - VLAN tag to apply to packets on this interface. (1 - 4094) 244 | ** firewall : Default: false - Whether this interface should be protected by the firewall 245 | ** rate : - Rate limit in mbps (megabytes per second) as floating point number. (0 - N) 246 | ** queues : - Number of packet queues to be used on the device. (0 - 16) 247 | ** link_down : - Whether this interface should be disconnected (like pulling the plug) 248 | */ 249 | variable "network" { 250 | description = "Specify network devices" 251 | type = list(object({ 252 | model = string 253 | macaddr = string 254 | bridge = string 255 | tag = number 256 | firewall = bool 257 | rate = number 258 | queues = number 259 | link_down = bool 260 | })) 261 | default = [ 262 | { 263 | model = "virtio" 264 | macaddr = null 265 | bridge = "vmbr0" 266 | tag = null 267 | firewall = false 268 | rate = null 269 | queues = null 270 | link_down = false 271 | } 272 | ] 273 | } 274 | 275 | /* 276 | ** type : REQUIRED - Disk Type - (ide|sata|scsi|virtio) 277 | ** storage : REQUIRED - Target storage 278 | ** size : REQUIRED - Disk size. This is purely informational and has no effect 279 | ** format : - Set the drive’s backing file’s data format (cloop | cow | qcow | qcow2 | qed | raw | vmdk) 280 | ** cache : Default: "none" - Set the drive’s cache mode (directsync | none | unsafe | writeback | writethrough) 281 | ** backup : Default: false - Whether the drive should be included when making backups 282 | ** iothread : Default: false - Whether to use iothreads for this drive 283 | ** replicate : Default: false - Whether the drive should considered for replication jobs 284 | ** ssd : - Whether to expose this drive as an SSD, rather than a rotational hard disk 285 | ** discard : - Controls whether to pass discard/trim requests to the underlying storage 286 | ** mbps : Default: 0 - Maximum r/w speed in megabytes per second 287 | ** mbps_rd : Default: 0 - Maximum read speed in megabytes per second 288 | ** mbps_rd_max : Default: 0 - Maximum unthrottled read pool in megabytes per second 289 | ** mbps_wr : Default: 0 - Maximum write speed in megabytes per second 290 | ** mbps_wr_max : Default: 0 - Maximum unthrottled write pool in megabytes per second 291 | ** file : - The drive’s backing volume 292 | ** media : - Set the drive’s media type (cdrom | disk) 293 | ** volume : - 294 | ** slot : - 295 | */ 296 | variable "disk" { 297 | description = "Specify disk variables" 298 | type = list(object({ 299 | type = string 300 | storage = string 301 | size = string 302 | format = string 303 | cache = string 304 | backup = bool 305 | iothread = bool 306 | replicate = bool 307 | ssd = bool 308 | discard = string 309 | mbps = number 310 | mbps_rd = number 311 | mbps_rd_max = number 312 | mbps_wr = number 313 | mbps_wr_max = number 314 | file = string 315 | media = string 316 | volume = string 317 | slot = number 318 | })) 319 | default = [ 320 | { 321 | type = "scsi" 322 | storage = "local-lvm" 323 | size = "32G" 324 | format = "raw" 325 | cache = "none" 326 | backup = true 327 | iothread = true 328 | replicate = true 329 | ssd = null 330 | discard = "on" 331 | mbps = null 332 | mbps_rd = null 333 | mbps_rd_max = null 334 | mbps_wr = null 335 | mbps_wr_max = null 336 | file = null 337 | media = "disk" 338 | volume = null 339 | slot = null 340 | } 341 | ] 342 | } 343 | 344 | /* 345 | ** id : REQUIRED - ID is 0 to 3 346 | ** type : REQUIRED - socket 347 | */ 348 | variable "serial" { 349 | description = "Create a serial device inside the VM. Serial interface of type socket is used by xterm.js. Using a serial device as terminal" 350 | type = object({ 351 | id = number 352 | type = string 353 | }) 354 | default = { 355 | id = 0 356 | type = "socket" 357 | } 358 | } 359 | 360 | variable "pool" { 361 | description = "The destination resource pool for the new VM" 362 | type = string 363 | default = null 364 | } 365 | 366 | variable "force_create" { 367 | description = "Default: false" 368 | type = string 369 | default = false 370 | } 371 | 372 | variable "clone_wait" { 373 | description = "Giving time(second) to Proxmox-VE to catchup. Default: 15" 374 | type = number 375 | default = null 376 | } 377 | 378 | ######################################################################################### 379 | # ** The following arguments are specifically for Linux for preprovisioning ** 380 | # ** It phase which is used to set a hostname, intialize eth0, and resize the VM disk ** 381 | # ** REQUIRES define_connection_info to be TRUE ** 382 | ######################################################################################### 383 | variable "define_connection_info" { 384 | description = "Define the (SSH) connection parameters for preprovisioners. It allow user to opt-out of setting the connection info for the resource. Default: true" 385 | type = bool 386 | default = true 387 | } 388 | 389 | variable "preprovision" { 390 | description = "Enable/Disabled Pre-Provisioning. For more detail Telmate vm_qemu.md. Default: true" 391 | type = bool 392 | default = true 393 | } 394 | 395 | variable "os_type" { 396 | description = "Which provisioning method to use, based on the OS type. Possible values: ubuntu, centos, cloud-init. For more detail Telmate vm_qemu.md" 397 | type = string 398 | default = "cloud-init" 399 | } 400 | 401 | variable "os_network_config" { 402 | description = "Linux provisioning specific, /etc/network/interfaces for Ubuntu and /etc/sysconfig/network-scripts/ifcfg-eth0 for CentOS" 403 | type = string 404 | default = null 405 | } 406 | 407 | variable "ssh_forward_ip" { 408 | description = "Address used to connect to the VM" 409 | type = string 410 | default = null 411 | } 412 | 413 | variable "ssh_host" { 414 | description = "Hostname or IP Address used to connect to the VM" 415 | type = string 416 | default = null 417 | } 418 | 419 | variable "ssh_port" { 420 | description = "SSH port used to connect to the VM" 421 | type = string 422 | default = null 423 | } 424 | 425 | variable "ssh_user" { 426 | description = "Username to login in the VM when preprovisioning" 427 | type = string 428 | default = null 429 | } 430 | 431 | variable "ssh_private_key" { 432 | description = "Private key to login in the VM when preprovisioning" 433 | type = string 434 | default = null 435 | } 436 | 437 | ######################################################################################### 438 | # Arguments are supported in the Terraform Telmate Proxmox 439 | # ** Resource Block Cloud Init Specific Variables ** 440 | # ** Also the following arguments are specifically for Cloud-init for preprovisioning ** 441 | ######################################################################################### 442 | 443 | variable "ci_wait" { 444 | description = "Cloud-init specific, how to long to wait for preprovisioning. Default: 30" 445 | type = number 446 | default = null 447 | } 448 | 449 | variable "ciuser" { 450 | description = "Cloud-init specific, Overwrite image Default User" 451 | type = string 452 | default = null 453 | } 454 | 455 | variable "cipassword" { 456 | description = "Cloud-init specific, Password to assign the user. Using this is generally not recommended. Use ssh keys instead" 457 | type = string 458 | default = null 459 | } 460 | 461 | variable "cicustom" { 462 | description = "Cloud-init specific, location of the custom cloud-config files" 463 | type = string 464 | default = null 465 | } 466 | 467 | variable "searchdomain" { 468 | description = "Cloud-init specific, sets DNS search domains for a container" 469 | type = string 470 | default = null 471 | } 472 | 473 | variable "nameserver" { 474 | description = "Cloud-init specific, sets DNS server IP address for a container" 475 | type = string 476 | default = null 477 | } 478 | 479 | variable "sshkeys" { 480 | description = "Setup public SSH keys (one key per line, OpenSSH format)" 481 | type = string 482 | default = null 483 | } 484 | 485 | variable "ipconfig0" { 486 | description = "Cloud-init specific, Specify IP addresses and gateways for the corresponding interface. [gw=] [,gw6=] [,ip=] [,ip6=]" 487 | type = string 488 | default = null 489 | } 490 | 491 | variable "ipconfig1" { 492 | description = "Cloud-init specific, Specify IP addresses and gateways for the corresponding interface. [gw=] [,gw6=] [,ip=] [,ip6=]" 493 | type = string 494 | default = null 495 | } 496 | 497 | variable "ipconfig2" { 498 | description = "Cloud-init specific, Specify IP addresses and gateways for the corresponding interface. [gw=] [,gw6=] [,ip=] [,ip6=]" 499 | type = string 500 | default = null 501 | } 502 | 503 | variable "force_recreate_on_change_of" { 504 | description = "Allows this to depend on another resource, that when changed, needs to re-create this vm. An example where this is useful is a cloudinit configuration (as the cicustom attribute points to a file not the content)" 505 | type = string 506 | default = null 507 | } 508 | -------------------------------------------------------------------------------- /terraform/versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 0.13.5" 3 | required_providers { 4 | proxmox = { 5 | source = "Telmate/proxmox" 6 | version = "2.6.5" 7 | } 8 | } 9 | } --------------------------------------------------------------------------------