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/scaleway: fix security_group_rule identification #8661

Merged
merged 1 commit into from
Sep 6, 2016
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 @@ -89,8 +89,16 @@ func resourceScalewaySecurityGroupRuleCreate(d *schema.ResourceData, m interface
return err
}

matches := func(rule api.ScalewaySecurityGroupRule) bool {
return rule.Action == req.Action &&
rule.Direction == req.Direction &&
rule.IPRange == req.IPRange &&
rule.Protocol == req.Protocol &&
rule.DestPortFrom == req.DestPortFrom
}

for _, rule := range resp.Rules {
if rule.Action == req.Action && rule.Direction == req.Direction && rule.IPRange == req.IPRange && rule.Protocol == req.Protocol {
if matches(rule) {
d.SetId(rule.ID)
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ func TestAccScalewaySecurityGroupRule_Basic(t *testing.T) {
Config: testAccCheckScalewaySecurityGroupRuleConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewaySecurityGroupsExists("scaleway_security_group.base", &group),
resource.TestCheckResourceAttr("scaleway_security_group_rule.http", "action", "drop"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.http", "action", "accept"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.http", "direction", "inbound"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.http", "ip_range", "0.0.0.0/0"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.http", "protocol", "TCP"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.http", "port", "80"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.https", "action", "accept"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.https", "direction", "inbound"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.https", "ip_range", "0.0.0.0/0"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.https", "protocol", "TCP"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.https", "port", "443"),
testAccCheckScalewaySecurityGroupRuleExists("scaleway_security_group_rule.http", &group),
testAccCheckScalewaySecurityGroupRuleAttributes("scaleway_security_group_rule.http", &group),
),
Expand Down Expand Up @@ -93,7 +99,7 @@ func testAccCheckScalewaySecurityGroupRuleAttributes(n string, group *api.Scalew
return err
}

if rule.Rules.Action != "drop" {
if rule.Rules.Action != "accept" {
return fmt.Errorf("Wrong rule action")
}
if rule.Rules.Direction != "inbound" {
Expand Down Expand Up @@ -149,10 +155,20 @@ resource "scaleway_security_group" "base" {
resource "scaleway_security_group_rule" "http" {
security_group = "${scaleway_security_group.base.id}"

action = "drop"
action = "accept"
direction = "inbound"
ip_range = "0.0.0.0/0"
protocol = "TCP"
port = 80
}

resource "scaleway_security_group_rule" "https" {
security_group = "${scaleway_security_group.base.id}"

action = "accept"
direction = "inbound"
ip_range = "0.0.0.0/0"
protocol = "TCP"
port = 443
}
`