Skip to content

Commit

Permalink
changing ssh to use file content instead of file name
Browse files Browse the repository at this point in the history
  • Loading branch information
Maigard committed Dec 30, 2017
1 parent e5ec777 commit 1916a54
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions ovirt/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package ovirt

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

"github.com/EMSL-MSC/ovirtapi"
"github.com/hashicorp/terraform/helper/schema"
Expand All @@ -23,7 +23,8 @@ func resourceVM() *schema.Resource {
},
"cluster": {
Type: schema.TypeString,
Required: true,
Optional: true,
Default: "Default",
},
"template": {
Type: schema.TypeString,
Expand All @@ -35,8 +36,9 @@ func resourceVM() *schema.Resource {
Optional: true,
},
"authorized_ssh_key": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: checkAuthorizedSSHKey,
},
"network_interface": {
Type: schema.TypeList,
Expand Down Expand Up @@ -100,6 +102,7 @@ func resourceVMCreate(d *schema.ResourceData, meta interface{}) error {
if err != nil {
return err
}
d.Set("authorized_ssh_key", string(sshKey))
newVM.Initialization.AuthorizedSSHKeys = string(sshKey)
}

Expand Down Expand Up @@ -171,6 +174,7 @@ func resourceVMRead(d *schema.ResourceData, meta interface{}) error {
return nil
}
d.Set("template", template.Name)
d.Set("authorized_ssh_key", vm.Initialization.AuthorizedSSHKeys)
return nil
}

Expand All @@ -189,3 +193,11 @@ 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 1916a54

Please sign in to comment.