From 7e15b2ef07b2f7ff21dcaaa20bebc8afac173af7 Mon Sep 17 00:00:00 2001 From: Gavin Williams Date: Sat, 5 Nov 2016 10:06:49 +0000 Subject: [PATCH] provider/openstack: Add 'value_specs' option to 'openstack_fw_firewall_v1' resource Refactor to use common 'types.go' and 'MapValueSpecs' function. Website docs updated to reflect changes. --- .../resource_openstack_fw_firewall_v1.go | 20 +++++++++++++------ builtin/providers/openstack/types.go | 14 ++++++++++++- .../openstack/r/fw_firewall_v1.html.markdown | 2 ++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/builtin/providers/openstack/resource_openstack_fw_firewall_v1.go b/builtin/providers/openstack/resource_openstack_fw_firewall_v1.go index ed86278fede1..dd0b70798efe 100644 --- a/builtin/providers/openstack/resource_openstack_fw_firewall_v1.go +++ b/builtin/providers/openstack/resource_openstack_fw_firewall_v1.go @@ -51,6 +51,11 @@ func resourceFWFirewallV1() *schema.Resource { ForceNew: true, Computed: true, }, + "value_specs": &schema.Schema{ + Type: schema.TypeMap, + Optional: true, + ForceNew: true, + }, }, } } @@ -65,12 +70,15 @@ func resourceFWFirewallV1Create(d *schema.ResourceData, meta interface{}) error adminStateUp := d.Get("admin_state_up").(bool) - firewallConfiguration := firewalls.CreateOpts{ - Name: d.Get("name").(string), - Description: d.Get("description").(string), - PolicyID: d.Get("policy_id").(string), - AdminStateUp: &adminStateUp, - TenantID: d.Get("tenant_id").(string), + firewallConfiguration := FirewallCrateOpts{ + firewalls.CreateOpts{ + Name: d.Get("name").(string), + Description: d.Get("description").(string), + PolicyID: d.Get("policy_id").(string), + AdminStateUp: &adminStateUp, + TenantID: d.Get("tenant_id").(string), + }, + MapValueSpecs(d), } log.Printf("[DEBUG] Create firewall: %#v", firewallConfiguration) diff --git a/builtin/providers/openstack/types.go b/builtin/providers/openstack/types.go index 4f6a905c17af..c28081cd0e65 100644 --- a/builtin/providers/openstack/types.go +++ b/builtin/providers/openstack/types.go @@ -11,7 +11,19 @@ import ( "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" ) -// FloatingIPCreateOpts represents the attributes used when creating a new port. +// FirewallCreateOpts represents the attributes used when creating a new firewall. +type FirewallCreateOpts struct { + firewalls.CreateOpts + ValueSpecs map[string]string `json:"value_specs,omitempty"` +} + +// ToFirewallCreateMap casts a CreateOpts struct to a map. +// It overrides firewalls.ToFirewallCreateMap to add the ValueSpecs field. +func (opts FirewallCreateOpts) ToFirewallCreateMap() (map[string]interface{}, error) { + return BuildRequest(opts, "firewall") +} + +// FloatingIPCreateOpts represents the attributes used when creating a new floating ip. type FloatingIPCreateOpts struct { floatingips.CreateOpts ValueSpecs map[string]string `json:"value_specs,omitempty"` diff --git a/website/source/docs/providers/openstack/r/fw_firewall_v1.html.markdown b/website/source/docs/providers/openstack/r/fw_firewall_v1.html.markdown index 48fbc6b6025d..6d1ed9f64c17 100644 --- a/website/source/docs/providers/openstack/r/fw_firewall_v1.html.markdown +++ b/website/source/docs/providers/openstack/r/fw_firewall_v1.html.markdown @@ -69,6 +69,8 @@ The following arguments are supported: to create a firewall for another tenant. Changing this creates a new firewall. +* `value_specs` - (Optional) Map of additional options. + ## Attributes Reference The following attributes are exported: