diff --git a/README.md b/README.md index a7f67a7..419c827 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ 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 @@ -45,7 +45,15 @@ resource "proxmox_vm_qemu" "test" { disk_gb = 4 nic = "virtio" bridge = "vmbr1" - os_type = "ubnutu" + ssh_forward_ip = "10.0.0.1" + ssh_user = "terraform" + ssh_private_key = < /tmp/test") + + comm.Disconnect() + + return err +} + +// runCommand is used to run already prepared commands +func runCommand( + comm communicator.Communicator, + command string) error { + + _, outW := io.Pipe() + _, errW := io.Pipe() + //outDoneCh := make(chan struct{}) + //errDoneCh := make(chan struct{}) + // go copyOutput(o, outR, outDoneCh) + // go copyOutput(o, errR, errDoneCh) + + cmd := &remote.Cmd{ + Command: command, + Stdout: outW, + Stderr: errW, + } + + err := comm.Start(cmd) + if err != nil { + return fmt.Errorf("Error executing command %q: %v", cmd.Command, err) + } + + cmd.Wait() + if cmd.ExitStatus != 0 { + err = fmt.Errorf( + "Command %q exited with non-zero exit status: %d", cmd.Command, cmd.ExitStatus) + } + + // Wait for output to clean up + outW.Close() + errW.Close() + //<-outDoneCh + //<-errDoneCh + + return err +} + +// +// func copyOutput(o terraform.UIOutput, r io.Reader, doneCh chan<- struct{}) { +// defer close(doneCh) +// lr := linereader.New(r) +// for line := range lr.Ch { +// o.Output(line) +// } +// } diff --git a/proxmox/resource_vm_qemu.go b/proxmox/resource_vm_qemu.go index 1ad074b..3ab75a0 100644 --- a/proxmox/resource_vm_qemu.go +++ b/proxmox/resource_vm_qemu.go @@ -87,6 +87,16 @@ func resourceVmQemu() *schema.Resource { Optional: true, ForceNew: true, }, + "ssh_user": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "ssh_private_key": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, }, } } @@ -151,13 +161,24 @@ func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error { } d.SetConnInfo(map[string]string{ - "type": "ssh", - "host": d.Get("ssh_forward_ip").(string), - "port": sshPort, + "type": "ssh", + "host": d.Get("ssh_forward_ip").(string), + "port": sshPort, + "user": d.Get("ssh_user").(string), + "private_key": d.Get("ssh_private_key").(string), }) - // TODO - preprovision VM (setup eth0 and hostname) + switch d.Get("os_type").(string) { + case "ubuntu": + err = preProvisionUbuntu(d) + if err != nil { + return err + } + + default: + return fmt.Errorf("Unknown os_type: %s", d.Get("os_type").(string)) + } return nil }