diff --git a/builtin/providers/cloudstack/resource_cloudstack_ssh_keypair.go b/builtin/providers/cloudstack/resource_cloudstack_ssh_keypair.go index 5235985d7..a418c4cf6 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_ssh_keypair.go +++ b/builtin/providers/cloudstack/resource_cloudstack_ssh_keypair.go @@ -62,9 +62,11 @@ func resourceCloudStackSSHKeyPairCreate(d *schema.ResourceData, meta interface{} } p := cs.SSH.NewRegisterSSHKeyPairParams(name, string(key)) + if err := setProjectid(p, cs, d); err != nil { return err } + _, err = cs.SSH.RegisterSSHKeyPair(p) if err != nil { return err @@ -72,9 +74,11 @@ func resourceCloudStackSSHKeyPairCreate(d *schema.ResourceData, meta interface{} } else { // No key supplied, must create one and return the private key p := cs.SSH.NewCreateSSHKeyPairParams(name) + if err := setProjectid(p, cs, d); err != nil { return err } + r, err := cs.SSH.CreateSSHKeyPair(p) if err != nil { return err @@ -95,6 +99,7 @@ func resourceCloudStackSSHKeyPairRead(d *schema.ResourceData, meta interface{}) p := cs.SSH.NewListSSHKeyPairsParams() p.SetName(d.Id()) + if err := setProjectid(p, cs, d); err != nil { return err } @@ -121,6 +126,7 @@ func resourceCloudStackSSHKeyPairDelete(d *schema.ResourceData, meta interface{} // Create a new parameter struct p := cs.SSH.NewDeleteSSHKeyPairParams(d.Id()) + if err := setProjectid(p, cs, d); err != nil { return err } diff --git a/builtin/providers/cloudstack/resources.go b/builtin/providers/cloudstack/resources.go index 3e781fd4a..5421cb101 100644 --- a/builtin/providers/cloudstack/resources.go +++ b/builtin/providers/cloudstack/resources.go @@ -196,5 +196,6 @@ func setProjectid(p projectidSetter, cs *cloudstack.CloudStackClient, d *schema. } p.SetProjectid(projectid) } + return nil } diff --git a/website/source/docs/providers/cloudstack/r/ssh_keypair.html.markdown b/website/source/docs/providers/cloudstack/r/ssh_keypair.html.markdown index 372d1f488..5cfa47b10 100644 --- a/website/source/docs/providers/cloudstack/r/ssh_keypair.html.markdown +++ b/website/source/docs/providers/cloudstack/r/ssh_keypair.html.markdown @@ -28,10 +28,11 @@ The following arguments are supported: within a CloudStack account. Changing this forces a new resource to be created. -* `public_key` - (Optional) The public key in OpenSSH - `authorized_keys` format. If this is omitted, CloudStack will - generate a new key pair. Changing this forces a new resource to be - created. +* `public_key` - (Optional) The public key to register with CloudStack. If + this is omitted, CloudStack will generate a new key pair. The key can + be loaded from a file on disk using the [`file()` interpolation + function](/docs/configuration/interpolation.html#file_path_). Changing + this forces a new resource to be created. * `project` - (Optional) The name or ID of the project to register this key to. Changing this forces a new resource to be created.