From 92ac6dc1e35a756c2f885da76466bdd59362ca46 Mon Sep 17 00:00:00 2001 From: Ken Schmidt Date: Tue, 2 Jan 2018 10:22:51 -0800 Subject: [PATCH] changed ssh key to be content instead of file name --- main.tf | 7 +++++-- ovirt/resource_vm.go | 25 ++++--------------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/main.tf b/main.tf index 1f7af023..33501f6e 100644 --- a/main.tf +++ b/main.tf @@ -1,12 +1,15 @@ +variable "ovirt_pass" {} + provider "ovirt" { username = "kschmidt@PNL.GOV" 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" @@ -14,7 +17,7 @@ resource "ovirt_vm" "my_vm" { gateway = "130.20.232.1" subnet_mask = "255.255.255.0" } - + template = "centos-7.4.1707-cloudinit-mgmt" provisioner "remote-exec" { inline = [ diff --git a/ovirt/resource_vm.go b/ovirt/resource_vm.go index 007e251a..e5d542e1 100644 --- a/ovirt/resource_vm.go +++ b/ovirt/resource_vm.go @@ -2,7 +2,6 @@ package ovirt import ( "fmt" - "io/ioutil" "strconv" "time" @@ -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, @@ -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) @@ -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) -}