From 7438bbd7fe2ff0ab365d81f2118ac03b107927a8 Mon Sep 17 00:00:00 2001 From: Gavin Williams Date: Mon, 10 Oct 2016 11:25:06 +0100 Subject: [PATCH] provider/openstack: Add ValueSpecs option to 'openstack_compute_keypair_v2' resource, refactor to use common types.go and 'MapValueSpecs' --- .../resource_openstack_compute_keypair_v2.go | 14 +++++++++++--- builtin/providers/openstack/types.go | 13 +++++++++++++ .../openstack/r/compute_keypair_v2.html.markdown | 2 ++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/builtin/providers/openstack/resource_openstack_compute_keypair_v2.go b/builtin/providers/openstack/resource_openstack_compute_keypair_v2.go index e93c6e4f5..b5badb57c 100644 --- a/builtin/providers/openstack/resource_openstack_compute_keypair_v2.go +++ b/builtin/providers/openstack/resource_openstack_compute_keypair_v2.go @@ -34,6 +34,11 @@ func resourceComputeKeypairV2() *schema.Resource { Optional: true, ForceNew: true, }, + "value_specs": &schema.Schema{ + Type: schema.TypeMap, + Optional: true, + ForceNew: true, + }, }, } } @@ -45,9 +50,12 @@ func resourceComputeKeypairV2Create(d *schema.ResourceData, meta interface{}) er return fmt.Errorf("Error creating OpenStack compute client: %s", err) } - createOpts := keypairs.CreateOpts{ - Name: d.Get("name").(string), - PublicKey: d.Get("public_key").(string), + createOpts := KeyPairCreateOpts{ + keypairs.CreateOpts{ + Name: d.Get("name").(string), + PublicKey: d.Get("public_key").(string), + }, + MapValueSpecs(d), } log.Printf("[DEBUG] Create Options: %#v", createOpts) diff --git a/builtin/providers/openstack/types.go b/builtin/providers/openstack/types.go index 95a11ec0a..6a3906309 100644 --- a/builtin/providers/openstack/types.go +++ b/builtin/providers/openstack/types.go @@ -1,6 +1,7 @@ package openstack import ( + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" @@ -20,6 +21,18 @@ func (opts FloatingIPCreateOpts) ToFloatingIPCreateMap() (map[string]interface{} return BuildRequest(opts, "floatingip") } +// KeyPairCreateOpts represents the attributes used when creating a new keypair. +type KeyPairCreateOpts struct { + keypairs.CreateOpts + ValueSpecs map[string]string `json:"value_specs,omitempty"` +} + +// ToKeyPairCreateMap casts a CreateOpts struct to a map. +// It overrides keypairs.ToKeyPairCreateMap to add the ValueSpecs field. +func (opts KeyPairCreateOpts) ToKeyPairCreateMap() (map[string]interface{}, error) { + return BuildRequest(opts, "keypair") +} + // NetworkCreateOpts represents the attributes used when creating a new network. type NetworkCreateOpts struct { networks.CreateOpts diff --git a/website/source/docs/providers/openstack/r/compute_keypair_v2.html.markdown b/website/source/docs/providers/openstack/r/compute_keypair_v2.html.markdown index 8852385e7..5c1be0f6e 100644 --- a/website/source/docs/providers/openstack/r/compute_keypair_v2.html.markdown +++ b/website/source/docs/providers/openstack/r/compute_keypair_v2.html.markdown @@ -34,6 +34,8 @@ The following arguments are supported: * `public_key` - (Required) A pregenerated OpenSSH-formatted public key. Changing this creates a new keypair. +* `value_specs` - (Optional) Map of additional options. + ## Attributes Reference The following attributes are exported: