mirror of
https://github.com/letic/terraform-provider-proxmox.git
synced 2024-07-03 08:02:39 +00:00
provisioning a clone worked once
This commit is contained in:
parent
4510ee9073
commit
002598d0a3
38
README.md
38
README.md
|
@ -2,10 +2,46 @@
|
||||||
|
|
||||||
Terraform provider plugin for proxmox
|
Terraform provider plugin for proxmox
|
||||||
|
|
||||||
|
|
||||||
|
## Work in progress
|
||||||
|
|
||||||
|
### TODO
|
||||||
|
|
||||||
|
* document terraform-ubuntu1404-template creation process
|
||||||
|
* implement pre-provision phase
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
```
|
```
|
||||||
go build -o terraform-provider-proxmox
|
go build -o terraform-provider-proxmox
|
||||||
|
cp terraform-provider-proxmox $GOPATH/bin
|
||||||
```
|
```
|
||||||
|
|
||||||
## Work in progress
|
## Run
|
||||||
|
|
||||||
|
```
|
||||||
|
terraform apply
|
||||||
|
```
|
||||||
|
|
||||||
|
### Sample file
|
||||||
|
|
||||||
|
main.tf:
|
||||||
|
```
|
||||||
|
provider "proxmox" {
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "proxmox_vm_qemu" "test" {
|
||||||
|
name = "tftest1.xyz.com"
|
||||||
|
desc = "tf description"
|
||||||
|
target_node = "proxmox1-xx"
|
||||||
|
ssh_forward_ip = "10.0.0.1"
|
||||||
|
clone = "terraform-ubuntu1404-template"
|
||||||
|
storage = "local"
|
||||||
|
cores = 3
|
||||||
|
sockets = 1
|
||||||
|
memory = 2560
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ func Provider() *schema.Provider {
|
||||||
},
|
},
|
||||||
|
|
||||||
ResourcesMap: map[string]*schema.Resource{
|
ResourcesMap: map[string]*schema.Resource{
|
||||||
"vm_qemu": resourceVmQemu(),
|
"proxmox_vm_qemu": resourceVmQemu(),
|
||||||
// TODO - storage_iso
|
// TODO - storage_iso
|
||||||
// TODO - bridge
|
// TODO - bridge
|
||||||
// TODO - vm_qemu_template
|
// TODO - vm_qemu_template
|
||||||
|
|
|
@ -3,20 +3,21 @@ package proxmox
|
||||||
import (
|
import (
|
||||||
pxapi "github.com/Telmate/proxmox-api-go/proxmox"
|
pxapi "github.com/Telmate/proxmox-api-go/proxmox"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceVmQemu() *schema.Resource {
|
func resourceVmQemu() *schema.Resource {
|
||||||
|
*pxapi.Debug = true
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
Create: resourceVmQemuCreate,
|
Create: resourceVmQemuCreate,
|
||||||
Read: resourceVmQemuRead,
|
Read: resourceVmQemuRead,
|
||||||
Update: resourceVmQemuUpdate,
|
Update: nil, // TODO - updates?
|
||||||
Delete: resourceVmQemuDelete,
|
Delete: resourceVmQemuDelete,
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"vmid": {
|
"vmid": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Required: true,
|
Optional: true,
|
||||||
Computed: true,
|
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
|
@ -26,38 +27,127 @@ func resourceVmQemu() *schema.Resource {
|
||||||
},
|
},
|
||||||
"desc": {
|
"desc": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: false,
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
// memory
|
"target_node": {
|
||||||
// diskGB
|
Type: schema.TypeString,
|
||||||
// storage
|
Required: true,
|
||||||
// os
|
ForceNew: true,
|
||||||
// cores
|
},
|
||||||
// sockets
|
"ssh_forward_ip": {
|
||||||
// iso
|
Type: schema.TypeString,
|
||||||
// nic
|
Required: true,
|
||||||
// bridge
|
ForceNew: true,
|
||||||
// vlan
|
},
|
||||||
}}
|
"iso": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
"clone": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
"storage": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Required: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
"memory": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Required: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
"cores": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Required: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
"sockets": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Required: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
// TODO - diskGB
|
||||||
|
// TODO - os
|
||||||
|
// TODO - cores
|
||||||
|
// TODO - nic
|
||||||
|
// TODO - bridge
|
||||||
|
// TODO - vlan
|
||||||
|
// TODO - eth0 OS config
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
client := meta.(*providerConfiguration).Client
|
client := meta.(*providerConfiguration).Client
|
||||||
config := pxapi.ConfigQemu{
|
config := pxapi.ConfigQemu{
|
||||||
Name: d.Get("Name").(string),
|
Name: d.Get("name").(string),
|
||||||
Description: d.Get("desc").(string),
|
Description: d.Get("desc").(string),
|
||||||
|
Storage: d.Get("storage").(string),
|
||||||
|
Memory: d.Get("memory").(int),
|
||||||
|
QemuCores: d.Get("cores").(int),
|
||||||
|
QemuSockets: d.Get("sockets").(int),
|
||||||
|
// TODO - diskGB
|
||||||
|
// TODO - os
|
||||||
|
// TODO - nic
|
||||||
|
// TODO - bridge
|
||||||
|
// TODO - vlan
|
||||||
|
}
|
||||||
|
if d.Get("vmid").(int) == 0 {
|
||||||
|
maxid, err := pxapi.MaxVmId(client)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Println("MaxVmId: %d", maxid)
|
||||||
|
d.Set("vmid", maxid+1)
|
||||||
}
|
}
|
||||||
vmr := pxapi.NewVmRef(d.Get("vmid").(int))
|
vmr := pxapi.NewVmRef(d.Get("vmid").(int))
|
||||||
config.CreateVm(vmr, client)
|
vmr.SetNode(d.Get("target_node").(string))
|
||||||
|
|
||||||
|
// check if ISO or clone
|
||||||
|
if d.Get("clone").(string) != "" {
|
||||||
|
sourceVmr, err := client.GetVmRefByName(d.Get("clone").(string))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = config.CloneVm(sourceVmr, vmr, client)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// TODO - resize disk
|
||||||
|
} else if d.Get("iso").(string) != "" {
|
||||||
|
config.QemuIso = d.Get("iso").(string)
|
||||||
|
err := config.CreateVm(vmr, client)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, err := client.StartVm(vmr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
sshPort, err := pxapi.SshForwardUsernet(vmr, client)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
d.SetConnInfo(map[string]string{
|
||||||
|
"type": "ssh",
|
||||||
|
"host": d.Get("ssh_forward_ip").(string),
|
||||||
|
"port": sshPort,
|
||||||
|
})
|
||||||
|
|
||||||
|
// TODO - preprovision VM (setup eth0 and hostname)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceVmQemuRead(d *schema.ResourceData, meta interface{}) error {
|
func resourceVmQemuRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
return nil
|
return nil // all information in schema
|
||||||
}
|
|
||||||
|
|
||||||
func resourceVmQemuUpdate(d *schema.ResourceData, meta interface{}) error {
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceVmQemuDelete(d *schema.ResourceData, meta interface{}) error {
|
func resourceVmQemuDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user