From 60ddc06b3da0a3ef7f0c97e6db656dc5a73be6a9 Mon Sep 17 00:00:00 2001 From: Gavin Williams Date: Wed, 5 Oct 2016 17:23:30 +0100 Subject: [PATCH] provider/openstack: Add 'value_specs' option to 'openstack_networking_floatingip_v2' resource, refactor into common types.go and use new 'MapValueSpecs' function. Added supporting documentation. --- ...urce_openstack_networking_floatingip_v2.go | 19 ++++++++++++++----- builtin/providers/openstack/types.go | 13 +++++++++++++ .../r/networking_floatingip_v2.html.markdown | 2 ++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/builtin/providers/openstack/resource_openstack_networking_floatingip_v2.go b/builtin/providers/openstack/resource_openstack_networking_floatingip_v2.go index 429aab162..a660749e6 100644 --- a/builtin/providers/openstack/resource_openstack_networking_floatingip_v2.go +++ b/builtin/providers/openstack/resource_openstack_networking_floatingip_v2.go @@ -57,6 +57,11 @@ func resourceNetworkingFloatingIPV2() *schema.Resource { Optional: true, Computed: true, }, + "value_specs": &schema.Schema{ + Type: schema.TypeMap, + Optional: true, + ForceNew: true, + }, }, } } @@ -75,12 +80,16 @@ func resourceNetworkFloatingIPV2Create(d *schema.ResourceData, meta interface{}) if len(poolID) == 0 { return fmt.Errorf("No network found with name: %s", d.Get("pool").(string)) } - createOpts := floatingips.CreateOpts{ - FloatingNetworkID: poolID, - PortID: d.Get("port_id").(string), - TenantID: d.Get("tenant_id").(string), - FixedIP: d.Get("fixed_ip").(string), + createOpts := FloatingIPCreateOpts{ + floatingips.CreateOpts{ + FloatingNetworkID: poolID, + PortID: d.Get("port_id").(string), + TenantID: d.Get("tenant_id").(string), + FixedIP: d.Get("fixed_ip").(string), + }, + MapValueSpecs(d), } + log.Printf("[DEBUG] Create Options: %#v", createOpts) floatingIP, err := floatingips.Create(networkingClient, createOpts).Extract() if err != nil { diff --git a/builtin/providers/openstack/types.go b/builtin/providers/openstack/types.go index fac584571..272028fec 100644 --- a/builtin/providers/openstack/types.go +++ b/builtin/providers/openstack/types.go @@ -1,11 +1,24 @@ package openstack import ( + "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" "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" ) +// FloatingIPCreateOpts represents the attributes used when creating a new port. +type FloatingIPCreateOpts struct { + floatingips.CreateOpts + ValueSpecs map[string]string `json:"value_specs,omitempty"` +} + +// ToFloatingIPCreateMap casts a CreateOpts struct to a map. +// It overrides floatingips.ToFloatingIPCreateMap to add the ValueSpecs field. +func (opts FloatingIPCreateOpts) ToFloatingIPCreateMap() (map[string]interface{}, error) { + return BuildRequest(opts, "floatingip") +} + // NetworkCreateOpts represents the attributes used when creating a new network. type NetworkCreateOpts struct { networks.CreateOpts diff --git a/website/source/docs/providers/openstack/r/networking_floatingip_v2.html.markdown b/website/source/docs/providers/openstack/r/networking_floatingip_v2.html.markdown index e96a503ee..f9dfb5cd3 100644 --- a/website/source/docs/providers/openstack/r/networking_floatingip_v2.html.markdown +++ b/website/source/docs/providers/openstack/r/networking_floatingip_v2.html.markdown @@ -45,6 +45,8 @@ The following arguments are supported: * `fixed_ip` - Fixed IP of the port to associate with this floating IP. Required if the port has multiple fixed IPs. +* `value_specs` - (Optional) Map of additional options. + ## Attributes Reference The following attributes are exported: