Skip to content

Commit

Permalink
provider/openstack: Add 'value_specs' option to 'openstack_fw_policy_…
Browse files Browse the repository at this point in the history
…v1' resource

Refactor to use common 'types.go' and 'MapValueSpecs' function.
Website docs updated to reflect additions
  • Loading branch information
fatmcgav committed Nov 4, 2016
1 parent 11ea4bd commit d3b2c15
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
20 changes: 14 additions & 6 deletions builtin/providers/openstack/resource_openstack_fw_policy_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func resourceFWPolicyV1() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"value_specs": &schema.Schema{
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
},
},
}
}
Expand All @@ -79,12 +84,15 @@ func resourceFWPolicyV1Create(d *schema.ResourceData, meta interface{}) error {

audited := d.Get("audited").(bool)

opts := policies.CreateOpts{
Name: d.Get("name").(string),
Description: d.Get("description").(string),
Audited: &audited,
TenantID: d.Get("tenant_id").(string),
Rules: rules,
opts := PolicyCreateOpts{
policies.CreateOpts{
Name: d.Get("name").(string),
Description: d.Get("description").(string),
Audited: &audited,
TenantID: d.Get("tenant_id").(string),
Rules: rules,
},
MapValueSpecs(d),
}

if r, ok := d.GetOk("shared"); ok {
Expand Down
13 changes: 13 additions & 0 deletions builtin/providers/openstack/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package openstack

import (
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers"
Expand Down Expand Up @@ -46,6 +47,18 @@ func (opts NetworkCreateOpts) ToNetworkCreateMap() (map[string]interface{}, erro
return BuildRequest(opts, "network")
}

// PolicyCreateOpts represents the attributes used when creating a new firewall policy.
type PolicyCreateOpts struct {
policies.CreateOpts
ValueSpecs map[string]string `json:"value_specs,omitempty"`
}

// ToPolicyCreateMap casts a CreateOpts struct to a map.
// It overrides policies.ToFirewallPolicyCreateMap to add the ValueSpecs field.
func (opts PolicyCreateOpts) ToFirewallPolicyCreateMap() (map[string]interface{}, error) {
return BuildRequest(opts, "firewall_policy")
}

// PortCreateOpts represents the attributes used when creating a new port.
type PortCreateOpts struct {
ports.CreateOpts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ The following arguments are supported:
`shared` status of an existing firewall policy. Only administrative users
can specify if the policy should be shared.

* `value_specs` - (Optional) Map of additional options.

## Attributes Reference

The following attributes are exported:
Expand Down

0 comments on commit d3b2c15

Please sign in to comment.