Merge pull request #9617 from jtopjian/openstack-fwaas-proto-any

provider/openstack: Allow any protocol in openstack_fw_rule_v1
This commit is contained in:
Joe Topjian 2016-10-26 12:56:11 -06:00 committed by GitHub
commit a946eb4d91
5 changed files with 175 additions and 91 deletions

View File

@ -88,11 +88,12 @@ func resourceFWRuleV1Create(d *schema.ResourceData, meta interface{}) error {
enabled := d.Get("enabled").(bool)
ipVersion := resourceFWRuleV1DetermineIPVersion(d.Get("ip_version").(int))
protocol := resourceFWRuleV1DetermineProtocol(d.Get("protocol").(string))
ruleConfiguration := rules.CreateOpts{
Name: d.Get("name").(string),
Description: d.Get("description").(string),
Protocol: d.Get("protocol").(string),
Protocol: protocol,
Action: d.Get("action").(string),
IPVersion: ipVersion,
SourceIPAddress: d.Get("source_ip_address").(string),
@ -103,11 +104,6 @@ func resourceFWRuleV1Create(d *schema.ResourceData, meta interface{}) error {
TenantID: d.Get("tenant_id").(string),
}
if v, ok := d.GetOk("ip_version"); ok {
ipVersion := resourceFWRuleV1DetermineIPVersion(v.(int))
ruleConfiguration.IPVersion = ipVersion
}
log.Printf("[DEBUG] Create firewall rule: %#v", ruleConfiguration)
rule, err := rules.Create(networkingClient, ruleConfiguration).Extract()
@ -139,7 +135,6 @@ func resourceFWRuleV1Read(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Read OpenStack Firewall Rule %s: %#v", d.Id(), rule)
d.Set("protocol", rule.Protocol)
d.Set("action", rule.Action)
d.Set("name", rule.Name)
d.Set("description", rule.Description)
@ -150,6 +145,12 @@ func resourceFWRuleV1Read(d *schema.ResourceData, meta interface{}) error {
d.Set("destination_port", rule.DestinationPort)
d.Set("enabled", rule.Enabled)
if rule.Protocol == "" {
d.Set("protocol", "any")
} else {
d.Set("protocol", rule.Protocol)
}
return nil
}
@ -259,3 +260,19 @@ func resourceFWRuleV1DetermineIPVersion(ipv int) gophercloud.IPVersion {
return ipVersion
}
func resourceFWRuleV1DetermineProtocol(p string) rules.Protocol {
var protocol rules.Protocol
switch p {
case "any":
protocol = rules.ProtocolAny
case "icmp":
protocol = rules.ProtocolICMP
case "tcp":
protocol = rules.ProtocolTCP
case "udp":
protocol = rules.ProtocolUDP
}
return protocol
}

View File

@ -73,6 +73,32 @@ func TestAccFWRuleV1_basic(t *testing.T) {
})
}
func TestAccFWRuleV1_anyProtocol(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckFWRuleV1Destroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testFirewallRuleAnyProtocol,
Check: resource.ComposeTestCheckFunc(
testAccCheckFWRuleV1Exists(
"openstack_fw_rule_v1.rule_1",
&rules.Rule{
Name: "rule_1",
Description: "Allow any protocol",
Protocol: "",
Action: "allow",
IPVersion: 4,
SourceIPAddress: "192.168.199.0/24",
Enabled: true,
}),
),
},
},
})
}
func testAccCheckFWRuleV1Destroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
@ -178,3 +204,15 @@ resource "openstack_fw_rule_v1" "accept_test" {
enabled = false
}
`
const testFirewallRuleAnyProtocol = `
resource "openstack_fw_rule_v1" "rule_1" {
name = "rule_1"
description = "Allow any protocol"
protocol = "any"
action = "allow"
ip_version = 4
source_ip_address = "192.168.199.0/24"
enabled = true
}
`

View File

@ -5,6 +5,25 @@ import (
"github.com/gophercloud/gophercloud/pagination"
)
type (
// Protocol represents a valid rule protocol
Protocol string
)
const (
// ProtocolAny is to allow any protocol
ProtocolAny Protocol = "any"
// ProtocolICMP is to allow the ICMP protocol
ProtocolICMP Protocol = "icmp"
// ProtocolTCP is to allow the TCP protocol
ProtocolTCP Protocol = "tcp"
// ProtocolUDP is to allow the UDP protocol
ProtocolUDP Protocol = "udp"
)
// ListOptsBuilder allows extensions to add additional parameters to the
// List request.
type ListOptsBuilder interface {
@ -76,7 +95,7 @@ type CreateOptsBuilder interface {
// CreateOpts contains all the values needed to create a new firewall rule.
type CreateOpts struct {
Protocol string `json:"protocol" required:"true"`
Protocol Protocol `json:"protocol" required:"true"`
Action string `json:"action" required:"true"`
TenantID string `json:"tenant_id,omitempty"`
Name string `json:"name,omitempty"`
@ -92,7 +111,16 @@ type CreateOpts struct {
// ToRuleCreateMap casts a CreateOpts struct to a map.
func (opts CreateOpts) ToRuleCreateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "firewall_rule")
b, err := gophercloud.BuildRequestBody(opts, "firewall_rule")
if err != nil {
return nil, err
}
if m := b["firewall_rule"].(map[string]interface{}); m["protocol"] == "any" {
m["protocol"] = nil
}
return b, nil
}
// Create accepts a CreateOpts struct and uses the values to create a new firewall rule

162
vendor/vendor.json vendored
View File

@ -964,242 +964,242 @@
{
"checksumSHA1": "WJ/6nt4LiRCzFQcaxfc/iodURPM=",
"path": "github.com/gophercloud/gophercloud",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "KHRGRGaThzPw7fpZ+h6enJbSyDY=",
"path": "github.com/gophercloud/gophercloud/openstack",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "PFD8SEqhArAy/6jRbIlYb5lp64k=",
"path": "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "Ucc8dbvgihRt/2YqLhBkBYXF8v0=",
"path": "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "w2wHF5eEBE89ZYlkS9GAJsSIq9U=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "pUlKsepGmWDd4PqPaK4W85pHsRU=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "RWwUliHD65cWApdEo4ckOcPSArg=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "tOmntqlmZ/r8aObUChNloddLhwk=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/schedulerhints",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "IZQJSUx3hRGbhGrkm9Vtk1GP5XY=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "ci4gzd7Uy9JC4NcQ2ms19pjtW6s=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "qBpGbX7LQMPATdO8XyQmU7IXDiI=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/startstop",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "5JuziAp9BSRA/z+8pTjVLTWeTw4=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/tenantnetworks",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "2VNgU0F9PDax5VKClvMLmbzuksw=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "a9xDFPigDjHlPlthknKlBduGvKY=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "UGeqrw3KdPNRwDxl315MAYyy/uY=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/images",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "8QsTL/u0QRMoQE9lJSE55/3YKvg=",
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/servers",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "1sVqsZBZBNhDXLY9XzjMkcOkcbg=",
"path": "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "q1VGeltZl57OidZ5UDxbMsnyV2g=",
"path": "github.com/gophercloud/gophercloud/openstack/identity/v2/tokens",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "6M6ofb8ri5G+sZ8OiExLi7irdx8=",
"path": "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "aTHxjMlfNXFJ3l2TZyvIwqt/3kM=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "14ZhP0wE/WCL/6oujcML755AaH4=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "NJPrshMavmYLjTt94rjAluVZRUw=",
"checksumSHA1": "sYET5A7WTyJ7dpuxR/VXYoReldw=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "0UcU/7oQbhlnYKoT+I+T403U8MQ=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "Mjt7GwFygyqPxygY8xZZnUasHmk=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "mCTz2rnyVfhjJ+AD/WihCNcYWiY=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/members",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "B2mtHvADREtFLam72wyijyQh/Ds=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/monitors",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "pTr22CKKJ26yvhgd0SRxFF4jkEs=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/pools",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "E7/Z7g5O9o+ge+8YklheTpKgWNw=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/vips",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "mhpwj5tPv7Uw5aUfC55fhLPBcKo=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "5efJz6UH7JCFeav5ZCCzicXCFTU=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "TVFgBTz7B6bb1R4TWdgAkbE1/fk=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "xirjw9vJIN6rmkT3T56bfPfOLUM=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "FKwSMrpQf7b3TcCOQfh+ovoBShA=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "CsS/kI3VeLcSHzMKviFVDwqwgvk=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "zKOhFTL5BDZPMC58ZzZkryjskno=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/networks",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "BE+CO3QrEGpIgv3Ee2ANZp1WtSo=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/ports",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "wY0MY7RpX0Z2Y0rMmrAuYS6cHYA=",
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "5XMyCSYDLmv/b54K3HNNNCJdnBk=",
"path": "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "TDOZnaS0TO0NirpxV1QwPerAQTY=",
"path": "github.com/gophercloud/gophercloud/openstack/utils",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"checksumSHA1": "pmpLcbUZ+EgLUmTbzMtGRq3haOU=",
"path": "github.com/gophercloud/gophercloud/pagination",
"revision": "5368725816dfa1fe57af073df5eee113641ac801",
"revisionTime": "2016-10-14T19:10:13Z"
"revision": "e3d6384a3714b335d075862e6eb0a681180643df",
"revisionTime": "2016-10-25T18:03:21Z"
},
{
"path": "github.com/gosimple/slug",

View File

@ -39,7 +39,8 @@ The following arguments are supported:
updates the `description` of an existing firewall rule.
* `protocol` - (Required) The protocol type on which the firewall rule operates.
Changing this updates the `protocol` of an existing firewall rule.
Valid values are: `tcp`, `udp`, `icmp`, and `any`. Changing this updates the
`protocol` of an existing firewall rule.
* `action` - (Required) Action to be taken ( must be "allow" or "deny") when the
firewall rule matches. Changing this updates the `action` of an existing