@@ -2,12 +2,11 @@ package cloudstack
22
33import (
44 "fmt"
5- "io/ioutil"
65 "log"
76 "strings"
87
8+ "github.com/hashicorp/terraform/helper/pathorcontents"
99 "github.com/hashicorp/terraform/helper/schema"
10- "github.com/mitchellh/go-homedir"
1110 "github.com/xanzy/go-cloudstack/cloudstack"
1211)
1312
@@ -30,6 +29,12 @@ func resourceCloudStackSSHKeyPair() *schema.Resource {
3029 ForceNew : true ,
3130 },
3231
32+ "project" : & schema.Schema {
33+ Type : schema .TypeString ,
34+ Optional : true ,
35+ ForceNew : true ,
36+ },
37+
3338 "private_key" : & schema.Schema {
3439 Type : schema .TypeString ,
3540 Computed : true ,
@@ -51,24 +56,25 @@ func resourceCloudStackSSHKeyPairCreate(d *schema.ResourceData, meta interface{}
5156
5257 if publicKey != "" {
5358 // Register supplied key
54- keyPath , err := homedir .Expand (publicKey )
55- if err != nil {
56- return fmt .Errorf ("Error expanding the public key path: %v" , err )
57- }
58-
59- key , err := ioutil .ReadFile (keyPath )
59+ key , _ , err := pathorcontents .Read (publicKey )
6060 if err != nil {
6161 return fmt .Errorf ("Error reading the public key: %v" , err )
6262 }
6363
6464 p := cs .SSH .NewRegisterSSHKeyPairParams (name , string (key ))
65+ if err := setProjectid (p , cs , d ); err != nil {
66+ return err
67+ }
6568 _ , err = cs .SSH .RegisterSSHKeyPair (p )
6669 if err != nil {
6770 return err
6871 }
6972 } else {
7073 // No key supplied, must create one and return the private key
7174 p := cs .SSH .NewCreateSSHKeyPairParams (name )
75+ if err := setProjectid (p , cs , d ); err != nil {
76+ return err
77+ }
7278 r , err := cs .SSH .CreateSSHKeyPair (p )
7379 if err != nil {
7480 return err
@@ -89,6 +95,9 @@ func resourceCloudStackSSHKeyPairRead(d *schema.ResourceData, meta interface{})
8995
9096 p := cs .SSH .NewListSSHKeyPairsParams ()
9197 p .SetName (d .Id ())
98+ if err := setProjectid (p , cs , d ); err != nil {
99+ return err
100+ }
92101
93102 r , err := cs .SSH .ListSSHKeyPairs (p )
94103 if err != nil {
@@ -112,6 +121,9 @@ func resourceCloudStackSSHKeyPairDelete(d *schema.ResourceData, meta interface{}
112121
113122 // Create a new parameter struct
114123 p := cs .SSH .NewDeleteSSHKeyPairParams (d .Id ())
124+ if err := setProjectid (p , cs , d ); err != nil {
125+ return err
126+ }
115127
116128 // Remove the SSH Keypair
117129 _ , err := cs .SSH .DeleteSSHKeyPair (p )
0 commit comments