Skip to content

Commit

Permalink
Merge pull request Telmate#67 from in0rdr/feature/pool
Browse files Browse the repository at this point in the history
Support setting pool for new VMs and clones (cloud-init)
  • Loading branch information
ggongaware committed Jul 14, 2019
2 parents 06d6363 + ff05902 commit 8ef7113
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ resource "proxmox_vm_qemu" "cloudinit-test" {
target_node = "proxmox1-xx"
clone = "ci-ubuntu-template"
# The destination resource pool for the new VM
pool = "pool0"
storage = "local"
cores = 3
sockets = 1
Expand Down Expand Up @@ -105,6 +109,10 @@ resource "proxmox_vm_qemu" "prepprovision-test" {
target_node = "proxmox1-xx"
clone = "terraform-ubuntu1404-template"
# The destination resource pool for the new VM
pool = "pool0"
cores = 3
sockets = 1
memory = 2560
Expand Down
3 changes: 3 additions & 0 deletions examples/cloudinit_example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ resource "proxmox_vm_qemu" "cloudinit-test" {
# this might not include the FQDN
target_node = "proxmox-server02"

# The destination resource pool for the new VM
pool = "pool0"

# The template name to clone this vm from
clone = "linux-cloudinit-template"

Expand Down
11 changes: 11 additions & 0 deletions proxmox/resource_vm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ func resourceVmQemu() *schema.Resource {
Default: true,
ConflictsWith: []string{"ssh_forward_ip", "ssh_user", "ssh_private_key", "os_type", "os_network_config"},
},
"pool": {
Type: schema.TypeString,
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -391,6 +395,7 @@ func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error {

forceCreate := d.Get("force_create").(bool)
targetNode := d.Get("target_node").(string)
pool := d.Get("pool").(string)

if dupVmr != nil && forceCreate {
pmParallelEnd(pconf)
Expand All @@ -411,7 +416,12 @@ func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error {
}
vmr = pxapi.NewVmRef(nextid)

// set target node and pool
vmr.SetNode(targetNode)
if pool != "" {
vmr.SetPool(pool)
}

// check if ISO or clone
if d.Get("clone").(string) != "" {
sourceVmr, err := client.GetVmRefByName(d.Get("clone").(string))
Expand Down Expand Up @@ -630,6 +640,7 @@ func resourceVmQemuRead(d *schema.ResourceData, meta interface{}) error {
d.Set("bridge", config.QemuBrige)
d.Set("vlan", config.QemuVlanTag)
d.Set("mac", config.QemuMacAddr)
d.Set("pool", vmr.Pool())

pmParallelEnd(pconf)
return nil
Expand Down

0 comments on commit 8ef7113

Please sign in to comment.