Skip to content

Commit

Permalink
changed ssh key to be content instead of file name
Browse files Browse the repository at this point in the history
  • Loading branch information
Maigard committed Jan 2, 2018
1 parent 37b0ea3 commit 92ac6dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
7 changes: 5 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
variable "ovirt_pass" {}

provider "ovirt" {
username = "[email protected]"
url = "https://ovirt.emsl.pnl.gov/ovirt-engine/api"
password = "${var.ovirt_pass}"
}

resource "ovirt_vm" "my_vm" {
name = "my_first_vm"
cluster = "Default"
authorized_ssh_key = "/Users/kschmidt/.ssh/id_rsa.pub"
authorized_ssh_key = "${file(pathexpand("~/.ssh/id_rsa.pub"))}"
network_interface {
label = "eth0"
boot_proto = "static"
ip_address = "130.20.232.184"
gateway = "130.20.232.1"
subnet_mask = "255.255.255.0"
}

template = "centos-7.4.1707-cloudinit-mgmt"
provisioner "remote-exec" {
inline = [
Expand Down
25 changes: 4 additions & 21 deletions ovirt/resource_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ovirt

import (
"fmt"
"io/ioutil"
"strconv"
"time"

Expand Down Expand Up @@ -36,9 +35,9 @@ func resourceVM() *schema.Resource {
Optional: true,
},
"authorized_ssh_key": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: checkAuthorizedSSHKey,
Type: schema.TypeString,
Optional: true,
Default: "",
},
"network_interface": {
Type: schema.TypeList,
Expand Down Expand Up @@ -96,15 +95,7 @@ func resourceVMCreate(d *schema.ResourceData, meta interface{}) error {

newVM.Initialization = &ovirtapi.Initialization{}

sshKeyFile := d.Get("authorized_ssh_key").(string)
if sshKeyFile != "" {
sshKey, err := ioutil.ReadFile(sshKeyFile)
if err != nil {
return err
}
d.Set("authorized_ssh_key", string(sshKey))
newVM.Initialization.AuthorizedSSHKeys = string(sshKey)
}
newVM.Initialization.AuthorizedSSHKeys = d.Get("authorized_ssh_key").(string)

numNetworks := d.Get("network_interface.#").(int)
NICConfigurations := make([]ovirtapi.NICConfiguration, numNetworks)
Expand Down Expand Up @@ -193,11 +184,3 @@ func resourceVMDelete(d *schema.ResourceData, meta interface{}) error {
}
return vm.Delete()
}

func checkAuthorizedSSHKey(k, old, new string, d *schema.ResourceData) bool {
sshKey, err := ioutil.ReadFile(new)
if err != nil {
return false
}
return old == string(sshKey)
}

0 comments on commit 92ac6dc

Please sign in to comment.