mirror of
https://github.com/letic/terraform-provider-proxmox.git
synced 2024-10-01 16:21:05 +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
|
||||
|
||||
|
||||
## Work in progress
|
||||
|
||||
### TODO
|
||||
|
||||
* document terraform-ubuntu1404-template creation process
|
||||
* implement pre-provision phase
|
||||
|
||||
## Build
|
||||
|
||||
```
|
||||
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{
|
||||
"vm_qemu": resourceVmQemu(),
|
||||
"proxmox_vm_qemu": resourceVmQemu(),
|
||||
// TODO - storage_iso
|
||||
// TODO - bridge
|
||||
// TODO - vm_qemu_template
|
||||
|
@ -3,20 +3,21 @@ package proxmox
|
||||
import (
|
||||
pxapi "github.com/Telmate/proxmox-api-go/proxmox"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"log"
|
||||
)
|
||||
|
||||
func resourceVmQemu() *schema.Resource {
|
||||
*pxapi.Debug = true
|
||||
return &schema.Resource{
|
||||
Create: resourceVmQemuCreate,
|
||||
Read: resourceVmQemuRead,
|
||||
Update: resourceVmQemuUpdate,
|
||||
Update: nil, // TODO - updates?
|
||||
Delete: resourceVmQemuDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"vmid": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"name": {
|
||||
@ -26,38 +27,127 @@ func resourceVmQemu() *schema.Resource {
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Required: false,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
// memory
|
||||
// diskGB
|
||||
// storage
|
||||
// os
|
||||
// cores
|
||||
// sockets
|
||||
// iso
|
||||
// nic
|
||||
// bridge
|
||||
// vlan
|
||||
}}
|
||||
"target_node": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"ssh_forward_ip": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"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 {
|
||||
client := meta.(*providerConfiguration).Client
|
||||
config := pxapi.ConfigQemu{
|
||||
Name: d.Get("Name").(string),
|
||||
Name: d.Get("name").(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))
|
||||
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
|
||||
}
|
||||
|
||||
func resourceVmQemuRead(d *schema.ResourceData, meta interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceVmQemuUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
return nil
|
||||
return nil // all information in schema
|
||||
}
|
||||
|
||||
func resourceVmQemuDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
|
Loading…
Reference in New Issue
Block a user