Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/openstack: Allow numerical protocols in security group rules #14917

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package openstack
import (
"fmt"
"log"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -229,6 +230,8 @@ func resourceNetworkingSecGroupRuleV2DetermineEtherType(v string) rules.RuleEthe

func resourceNetworkingSecGroupRuleV2DetermineProtocol(v string) rules.RuleProtocol {
var protocol rules.RuleProtocol

// Check and see if the requested protocol matched a list of known protocol names.
switch v {
case "tcp":
protocol = rules.ProtocolTCP
Expand Down Expand Up @@ -274,6 +277,14 @@ func resourceNetworkingSecGroupRuleV2DetermineProtocol(v string) rules.RuleProto
protocol = rules.ProtocolVRRP
}

// If the protocol wasn't matched above, see if it's an integer.
if protocol == "" {
_, err := strconv.Atoi(v)
if err == nil {
protocol = rules.RuleProtocol(v)
}
}

return protocol
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,30 @@ func TestAccNetworkingV2SecGroupRule_protocols(t *testing.T) {
})
}

func TestAccNetworkingV2SecGroupRule_numericProtocol(t *testing.T) {
var secgroup_1 groups.SecGroup
var secgroup_rule_1 rules.SecGroupRule

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNetworkingV2SecGroupRuleDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccNetworkingV2SecGroupRule_numericProtocol,
Check: resource.ComposeTestCheckFunc(
testAccCheckNetworkingV2SecGroupExists(
"openstack_networking_secgroup_v2.secgroup_1", &secgroup_1),
testAccCheckNetworkingV2SecGroupRuleExists(
"openstack_networking_secgroup_rule_v2.secgroup_rule_1", &secgroup_rule_1),
resource.TestCheckResourceAttr(
"openstack_networking_secgroup_rule_v2.secgroup_rule_1", "protocol", "115"),
),
},
},
})
}

func testAccCheckNetworkingV2SecGroupRuleDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
Expand Down Expand Up @@ -486,3 +510,20 @@ resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_vrrp" {
security_group_id = "${openstack_networking_secgroup_v2.secgroup_1.id}"
}
`

const testAccNetworkingV2SecGroupRule_numericProtocol = `
resource "openstack_networking_secgroup_v2" "secgroup_1" {
name = "secgroup_1"
description = "terraform security group rule acceptance test"
}

resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_1" {
direction = "ingress"
ethertype = "IPv4"
port_range_max = 22
port_range_min = 22
protocol = "115"
remote_ip_prefix = "0.0.0.0/0"
security_group_id = "${openstack_networking_secgroup_v2.secgroup_1.id}"
}
`