mirror of
https://github.com/letic/terraform-provider-proxmox.git
synced 2024-07-05 17:12:38 +00:00
Document login ENV.
Change agent default to match proxmox default
This commit is contained in:
parent
f7bc26dfe8
commit
24a4408337
152
README.md
152
README.md
|
@ -29,9 +29,21 @@ make install
|
||||||
|
|
||||||
Recommended ISO builder https://github.com/Telmate/terraform-ubuntu-proxmox-iso
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Run
|
## Run
|
||||||
|
|
||||||
```
|
```
|
||||||
|
terraform init
|
||||||
|
terraform plan
|
||||||
terraform apply
|
terraform apply
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -40,97 +52,103 @@ terraform apply
|
||||||
main.tf:
|
main.tf:
|
||||||
```
|
```
|
||||||
provider "proxmox" {
|
provider "proxmox" {
|
||||||
pm_tls_insecure = true
|
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"
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Uses cloud-init options from Proxmox 5.2 */
|
/* Uses cloud-init options from Proxmox 5.2 */
|
||||||
resource "proxmox_vm_qemu" "cloudinit-test" {
|
resource "proxmox_vm_qemu" "cloudinit-test" {
|
||||||
name = "tftest1.xyz.com"
|
name = "tftest1.xyz.com"
|
||||||
desc = "tf description"
|
desc = "tf description"
|
||||||
target_node = "proxmox1-xx"
|
target_node = "proxmox1-xx"
|
||||||
|
|
||||||
clone = "ci-ubuntu-template"
|
clone = "ci-ubuntu-template"
|
||||||
storage = "local"
|
storage = "local"
|
||||||
cores = 3
|
cores = 3
|
||||||
sockets = 1
|
sockets = 1
|
||||||
memory = 2560
|
memory = 2560
|
||||||
disk_gb = 4
|
disk_gb = 4
|
||||||
nic = "virtio"
|
nic = "virtio"
|
||||||
bridge = "vmbr0"
|
bridge = "vmbr0"
|
||||||
|
|
||||||
ssh_user = "root"
|
ssh_user = "root"
|
||||||
ssh_private_key = <<EOF
|
ssh_private_key = <<EOF
|
||||||
-----BEGIN RSA PRIVATE KEY-----
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
private ssh key root
|
private ssh key root
|
||||||
-----END RSA PRIVATE KEY-----
|
-----END RSA PRIVATE KEY-----
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
os_type = "cloud-init"
|
os_type = "cloud-init"
|
||||||
ipconfig0 = "ip=10.0.2.99, gw=10.0.2.2"
|
ipconfig0 = "ip=10.0.2.99, gw=10.0.2.2"
|
||||||
|
|
||||||
sshkeys = <<EOF
|
sshkeys = <<EOF
|
||||||
ssh-rsa AAAAB3NzaC1kj...key1
|
ssh-rsa AAAAB3NzaC1kj...key1
|
||||||
ssh-rsa AAAAB3NzaC1kj...key2
|
ssh-rsa AAAAB3NzaC1kj...key2
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
provisioner "remote-exec" {
|
provisioner "remote-exec" {
|
||||||
inline = [
|
inline = [
|
||||||
"ip a"
|
"ip a"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Uses custom eth1 user-net SSH portforward */
|
/* Uses custom eth1 user-net SSH portforward */
|
||||||
resource "proxmox_vm_qemu" "prepprovision-test" {
|
resource "proxmox_vm_qemu" "prepprovision-test" {
|
||||||
name = "tftest1.xyz.com"
|
name = "tftest1.xyz.com"
|
||||||
desc = "tf description"
|
desc = "tf description"
|
||||||
target_node = "proxmox1-xx"
|
target_node = "proxmox1-xx"
|
||||||
|
|
||||||
clone = "terraform-ubuntu1404-template"
|
clone = "terraform-ubuntu1404-template"
|
||||||
cores = 3
|
cores = 3
|
||||||
sockets = 1
|
sockets = 1
|
||||||
memory = 2560
|
memory = 2560
|
||||||
network {
|
network {
|
||||||
id = 0
|
id = 0
|
||||||
model = "virtio"
|
model = "virtio"
|
||||||
}
|
}
|
||||||
network {
|
network {
|
||||||
id = 1
|
id = 1
|
||||||
model = "virtio"
|
model = "virtio"
|
||||||
bridge = "vmbr1"
|
bridge = "vmbr1"
|
||||||
}
|
}
|
||||||
disk {
|
disk {
|
||||||
id = 0
|
id = 0
|
||||||
type = virtio
|
type = virtio
|
||||||
storage = local-lvm
|
storage = local-lvm
|
||||||
storage_type = lvm
|
storage_type = lvm
|
||||||
size = 4G
|
size = 4G
|
||||||
backup = true
|
backup = true
|
||||||
}
|
}
|
||||||
preprovision = true
|
preprovision = true
|
||||||
ssh_forward_ip = "10.0.0.1"
|
ssh_forward_ip = "10.0.0.1"
|
||||||
ssh_user = "terraform"
|
ssh_user = "terraform"
|
||||||
ssh_private_key = <<EOF
|
ssh_private_key = <<EOF
|
||||||
-----BEGIN RSA PRIVATE KEY-----
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
private ssh key terraform
|
private ssh key terraform
|
||||||
-----END RSA PRIVATE KEY-----
|
-----END RSA PRIVATE KEY-----
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
os_type = "ubuntu"
|
os_type = "ubuntu"
|
||||||
os_network_config = <<EOF
|
os_network_config = <<EOF
|
||||||
auto eth0
|
auto eth0
|
||||||
iface eth0 inet dhcp
|
iface eth0 inet dhcp
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
provisioner "remote-exec" {
|
provisioner "remote-exec" {
|
||||||
inline = [
|
inline = [
|
||||||
"ip a"
|
"ip a"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
provisioner "proxmox" {
|
provisioner "proxmox" {
|
||||||
action = "sshbackward"
|
action = "sshbackward"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -173,18 +191,18 @@ Disk resize is done if the file /etc/auto_resize_vda.sh exists. Source: https://
|
||||||
Remove the temporary net1 adapter.
|
Remove the temporary net1 adapter.
|
||||||
Inside the VM this usually triggers the routes back to the provisioning machine on net0.
|
Inside the VM this usually triggers the routes back to the provisioning machine on net0.
|
||||||
```
|
```
|
||||||
provisioner "proxmox" {
|
provisioner "proxmox" {
|
||||||
action = "sshbackward"
|
action = "sshbackward"
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Replace the temporary net1 adapter with a new persistent net1.
|
Replace the temporary net1 adapter with a new persistent net1.
|
||||||
```
|
```
|
||||||
provisioner "proxmox" {
|
provisioner "proxmox" {
|
||||||
action = "reconnect"
|
action = "reconnect"
|
||||||
net1 = "virtio,bridge=vmbr0,tag=99"
|
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.
|
If net1 needs a config other than DHCP you should prior to this use provisioner "remote-exec" to modify the network config.
|
||||||
|
|
|
@ -50,7 +50,7 @@ func resourceVmQemu() *schema.Resource {
|
||||||
"agent": {
|
"agent": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: 1,
|
Default: 0,
|
||||||
},
|
},
|
||||||
"iso": {
|
"iso": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
@ -66,6 +66,12 @@ func resourceVmQemu() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: "l26",
|
Default: "l26",
|
||||||
|
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
|
||||||
|
if new == "l26" {
|
||||||
|
return len(d.Get("clone").(string)) > 0 // the cloned source may have a different os, which we shoud leave alone
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(old) == strings.TrimSpace(new)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"memory": {
|
"memory": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
|
@ -589,6 +595,7 @@ func resourceVmQemuRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
d.Set("name", config.Name)
|
d.Set("name", config.Name)
|
||||||
d.Set("desc", config.Description)
|
d.Set("desc", config.Description)
|
||||||
d.Set("onboot", config.Onboot)
|
d.Set("onboot", config.Onboot)
|
||||||
|
d.Set("agent", config.Agent)
|
||||||
d.Set("memory", config.Memory)
|
d.Set("memory", config.Memory)
|
||||||
d.Set("cores", config.QemuCores)
|
d.Set("cores", config.QemuCores)
|
||||||
d.Set("sockets", config.QemuSockets)
|
d.Set("sockets", config.QemuSockets)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user