From 4806958d40f43014ac2fa81974a8cb0c5ccd24f4 Mon Sep 17 00:00:00 2001 From: Frederik Bosch Date: Wed, 11 Mar 2020 13:56:30 +0100 Subject: [PATCH] Enhance documentation, split into multiple files, start with adding argument references --- README.md | 343 ++------------------------------------- docs/cloud_init_guide.md | 219 +++++++++++++++++++++++++ docs/index.md | 10 ++ docs/installation.md | 41 +++++ docs/provider.md | 34 ++++ docs/provisioner.md | 20 +++ docs/resource_lxc.md | 1 + docs/resource_vm_qemu.md | 50 ++++++ docs/terraforminit.md | 27 --- 9 files changed, 389 insertions(+), 356 deletions(-) create mode 100644 docs/cloud_init_guide.md create mode 100644 docs/index.md create mode 100644 docs/installation.md create mode 100644 docs/provider.md create mode 100644 docs/provisioner.md create mode 100644 docs/resource_lxc.md create mode 100644 docs/resource_vm_qemu.md delete mode 100644 docs/terraforminit.md diff --git a/README.md b/README.md index 26e73475..26d6ad88 100644 --- a/README.md +++ b/README.md @@ -1,338 +1,23 @@ [![Build Status](https://travis-ci.com/Telmate/terraform-provider-proxmox.svg?branch=master)](https://travis-ci.com/Telmate/terraform-provider-proxmox) -# Proxmox 4 Terraform +# Terraform provider plugin for Proxmox -Terraform provider plugin for proxmox +This repository provides both a Terraform provider and provisioner for the [Promox virtualization platform](https://pve.proxmox.com/pve-docs/). +## Getting started -## Working prototype +In order to get started, use [the documentation included in this repository](docs/index.md). The documentation contains +a list of the options for both the provider and the provisioner. Moreover, there are some guides available how to combine +options and start specific VMs. +## Contributing -## Go Install +When contributing, please also add documentation to help other users. -``` -go install github.com/Telmate/terraform-provider-proxmox/cmd/terraform-provider-proxmox -go install github.com/Telmate/terraform-provider-proxmox/cmd/terraform-provisioner-proxmox -``` -Note: this plugin is both a provider and provisioner in one, which is why it needs two install commands. +## Useful links -## Build local source - -Requires https://github.com/Telmate/proxmox-api-go - -``` -make -make install -``` - -Recommended ISO builder https://github.com/Telmate/terraform-ubuntu-proxmox-iso - -## Credentials - -```bash -# Credentials and URL optionally defined in the environment -export PM_API_URL="https://xxxx.com:8006/api2/json" -export PM_USER=user@pam -export PM_PASS=password -``` -If a 2FA OTP code is required -```bash -# Optional 2FA OTP code -export PM_OTP=otpcode -``` - -## Run - -``` -terraform init -terraform plan -terraform apply -``` - -### Sample file - -main.tf: -``` -provider "proxmox" { - pm_tls_insecure = true - /* - // Credentials here or environment - pm_api_url = "https://proxmox-server01.example.com:8006/api2/json" - pm_password = "secret" - pm_user = "terraform-user@pve" - //Optional - pm_otp = "otpcode" - */ -} - -/* Uses cloud-init options from Proxmox 5.2 */ -resource "proxmox_vm_qemu" "cloudinit-test" { - name = "tftest1.xyz.com" - desc = "tf description" - target_node = "proxmox1-xx" - - clone = "ci-ubuntu-template" - - # The destination resource pool for the new VM - pool = "pool0" - - storage = "local" - cores = 3 - sockets = 1 - memory = 2560 - disk_gb = 4 - nic = "virtio" - bridge = "vmbr0" - - ssh_user = "root" - ssh_private_key = <] [,gw6=] [,ip=] [,ip6=] -* ipconfig1 - optional, same as ipconfig0 format - -Alternatively, cloud-init configuration can be customized with config files that reside in a volume in the Proxmox VE server. Use the attribute `cicustom` to indicate the location of these files. - -* cicustom - location of cloud-config files that Proxmox will put in the generated cloud-init config iso image, e.g. `cicustom = "user=local:snippets/user_data.yaml"`. For more info about this attribute, see the details of the parameter `--cicustom` in the section "Custom Cloud-Init Configuration" from the [Proxmox Cloud-Init support](https://pve.proxmox.com/wiki/Cloud-Init_Support) page. - -### Preprovision (internal alternative to Cloud-Init) - -There is a pre-provision phase which is used to set a hostname, intialize eth0, and resize the VM disk to available space. This is done over SSH with the ssh_forward_ip, ssh_user and ssh_private_key. - -Disk resize is done if the file /etc/auto_resize_vda.sh exists. Source: https://github.com/Telmate/terraform-ubuntu-proxmox-iso/blob/master/auto_resize_vda.sh - -### Provisioner usage - - -Remove the temporary net1 adapter. -Inside the VM this usually triggers the routes back to the provisioning machine on net0. -``` - provisioner "proxmox" { - action = "sshbackward" - } - -``` - -Replace the temporary net1 adapter with a new persistent net1. -``` - provisioner "proxmox" { - action = "reconnect" - net1 = "virtio,bridge=vmbr0,tag=99" - } - -``` -If net1 needs a config other than DHCP you should prior to this use provisioner "remote-exec" to modify the network config. +* [Proxmox](https://www.proxmox.com/en/) +* [Proxmox documentation](https://pve.proxmox.com/pve-docs/) +* [Terraform](https://www.terraform.io/) +* [Terraform documentation](https://www.terraform.io/docs/index.html) +* [Recommended ISO builder](https://github.com/Telmate/terraform-ubuntu-proxmox-iso) diff --git a/docs/cloud_init_guide.md b/docs/cloud_init_guide.md new file mode 100644 index 00000000..b16b6520 --- /dev/null +++ b/docs/cloud_init_guide.md @@ -0,0 +1,219 @@ +# Cloud Init Guide + +## Sample file + +main.tf: +``` +/* Uses cloud-init options from Proxmox 5.2 */ +resource "proxmox_vm_qemu" "cloudinit-test" { + name = "tftest1.xyz.com" + desc = "tf description" + target_node = "proxmox1-xx" + + clone = "ci-ubuntu-template" + + # The destination resource pool for the new VM + pool = "pool0" + + storage = "local" + cores = 3 + sockets = 1 + memory = 2560 + disk_gb = 4 + nic = "virtio" + bridge = "vmbr0" + + ssh_user = "root" + ssh_private_key = <] [,gw6=] [,ip=] [,ip6=] +* ipconfig1 - optional, same as ipconfig0 format + + +## Argument reference + +* `cicustom` - (Optional) Location of cloud-config files that Proxmox will put in the generated cloud-init config iso + image, e.g. `cicustom = "user=local:snippets/user_data.yaml"`. For more info about this attribute, see the details of + the parameter `--cicustom` in the section "Custom Cloud-Init Configuration" from the [Proxmox Cloud-Init support](https://pve.proxmox.com/wiki/Cloud-Init_Support) page. +* `ssh_forward_ip` - (Optional) IP or hostname of the target node or bridge IP. This is where proxmox will create a port + forward to your VM with via a user_net. (for pre-cloud-init provisioning). diff --git a/docs/terraforminit.md b/docs/terraforminit.md deleted file mode 100644 index 5c89d0aa..00000000 --- a/docs/terraforminit.md +++ /dev/null @@ -1,27 +0,0 @@ -# How to get terraform to recognize third party provider - -The default installation of terraform has no way of finding custom third party providers. This document shows you how to locate providers so that `terraform init` can find them and copy them to your working terraform directory when creating a new project. - -## Locate the provider binaries - -Assuming you have followed other directions the deafult locations for these binaries (on a mac at least) are as follows: - -```bash -which terraform-provider-proxmox -~/go-workspace/bin/terraform-provider-proxmox -which terraform-provisioner-proxmox -~/go-workspace/bin/terraform-provisioner-proxmox -``` - -## Copy provider binaries - -You need to copy these binaries to the ~/.terraform.d directory which will also need to have a plugins directory created: - -```shell -cd ~/.terraform.d -mkdir plugins -cd plugins -cp ~/go-workspace/bin/terraform-provider-proxmox . -cp ~/go-workspace/bin/terraform-provisioner-proxmox . -``` -Once this is done, simply create a new terraform directory and do usual terraforming (terraform init etc)